In the page effect, sometimes weProgramThe ID attribute cannot be added to the looping column, because there may be multiple identical IDs in the list, so the jquery ID selector is not available. In this case, we can use the class selector,
At the same time, we may also need to limit the operations on this node element to the current Div (or table ).Code:
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" />
< Title > Jquery Effect </ Title >
< Script SRC = "Http://common.cnblogs.com/script/jquery.js" Type = "Text/JavaScript" > </ Script >
< Script Type = "Text/JavaScript" >
// Expand Hidden Layer
$ (Document). Ready ( Function (){
$ ( " . Part " ). Click ( Function (){
VaR Hidep = $ ( This ). Next ();
If (Hidep.css ( ' Display ' ) = ' None ' ){
Hidep. Show ();
$ ( This ). Hide ();
}
Else {
Hidep. Hide ();
$ ( This ). Show ();
}
});
$ ( " . All " ). Click ( Function (){
VaR Hidep = $ ( This ). Prev ();
If (Hidep.css ( ' Display ' ) = ' None ' ){
Hidep. Show ();
$ ( This ). Hide ();
}
Else {
Hidep. Hide ();
$ ( This ). Show ();
}
});
});
</ Script >
</ Head >
< Body >
<! -- Div -->
< Div Class = 'Classa' >
< P Class = "Part" > Content 1 </ P >
< P Class = "All" Style = "Display: none" > Content 1, hahaha, I expanded it. Here is more content. </ P >
</ Div >
< Div Class = 'Classa' >
< P Class = "Part" > Content 2 </ P >
< P Class = "All" Style = "Display: none" > Content 2, hahaha, I expanded it. Here is more content. </ P >
</ Div >
< Div Class = 'Classa' >
< P Class = "Part" > Content 3 </ P >
< P Class = "All" Style = "Display: none" > Content 3, hahaha, I expanded it. Here is more content. </ P >
</ Div >
</ Body >
</ Html >
That is to say, I want to expand the hidden content in classa without affecting the content in other identical classa. In fact, the focus here isJquery next, PrevMethods can also be used in other scenarios.