Home > Web Front-end > JS Tutorial > JQuery index() method usage code_jquery

JQuery index() method usage code_jquery

WBOY
Release: 2016-05-16 18:25:51
Original
1053 people have browsed it

There are 19 Repeater controls on the homepage of the Student Department website. Tab switching between 6 div blocks.

You can’t write the methods one by one when switching tabs: (The code is as follows...)

Copy code The code is as follows:

$(function()
{
$("#tabs a:eq(0),#tabs2 a:eq(0),#dbt_l_t_tabs a :eq(0),#dbt_r_t_tabs a:eq(0)").addClass("m_on");
$("#tabs a:gt(0),#tabs2 a:gt(0),#dbt_l_t_tabs a:gt(0),#dbt_r_t_tabs a:gt(0)").addClass("m_out");
$("#tabs a,#tabs2 a,#dbt_l_t_tabs a,#dbt_r_t_tabs a").each (function(){
$(this).mouseover(function(){
if($(this).hasClass("m_out"))
{
var ab=$(this) .closest("li").closest("div").attr("id");
var ulid="ul_" ab;
var arra=$("#" ab " a");
var e=arra.index($(this));
$("#" ab " a").removeClass("m_on").addClass("m_out");
$(this ).removeClass("m_out").addClass("m_on");
$("#" ulid " ul").hide();
$("#" ulid " ul:eq(" e ")").show();
}
})
})
})

The assignment in line 23 uses JQuery's index method. Find the index value of an element of an object in the object.
An official explanation: $('li').index($('#bar')); The index parameter here uses single quotes. It always fails during testing. . Don't know why. Later, the object where $(this) is located is directly defined first: var arra=$("#" ab "a");.
The index can be returned successfully.
The following is one of the Tabs
Copy code The code is as follows:




  • News
    ;div class="w1bg">






  • Related labels:
    source:php.cn
    Previous article:Using replace combined with regular expressions in JavaScript to achieve the effect of replaceAll_javascript skills Next article:Live method and $.browser method usage code under JQuery_jquery
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Latest Articles by Author
    Latest Issues
    Related Topics
    More>
    Popular Recommendations
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template