Jquery index () method code

Source: Internet
Author: User

The home page of the student's website has 19 repeater controls. Switch the tabs of the six Div blocks.

For tabs switching, you cannot write one by one :(CodeAs follows ....)Copy codeThe 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 + "");
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 index method of jquery is used to assign values to the 23 rows. Search for the index value of an element of an object in this object.
An official note: $ ('lil'). Index ($ ('# bar'); here, the index parameter is enclosed in single quotes. Always fails during the test .. I don't know why. Then, the object where $ (this) is located is defined: var ARRA = $ ("#" + AB + "");.
You can return the index successfully.
Here is a tabs Copy code The Code is as follows: <Div class = "sh_topnew">
<Div class = "w1bg"> </div>
<Div id = "tabs">
<Li> <Div class = "w1bg"> </div> <a href = "list. aspx? Uid = 185 "> News </a> <Div class =" w1bg "> </div> </LI>
<Li> <Div class = "w1bg"> </div> <a href = "list. aspx? Uid = 160 "> group study </a> <Div class =" w1bg "> </div> </LI>
</Div>
<Div class = "w1bg"> </div>
<Div class = "w636">
<Div class = "w300"> </div>
<Div class = "w336" id = "ul_tabs"> <ul> </ul> <ul class = "nodis">
<Li> <a href = "show. aspx? Uid = 194 & id = 6393 "Title =" "> [] </a> 2010-05-17 </LI>
<Li> <a href = "show. aspx? Uid = 193 & id = 6392 "Title =" Our Youth League Committee conducts main activities of style study construction "> [Group Day activities] Our Youth League Committee conducts main activities of style study construction </a> 2010-05-17 </LI>
</Ul> </div>
</Div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.