Jquery operation object array element method details, jquery Array
The Code is as follows:
Copy codeThe Code is as follows:
<Div id = "div1">
<Span> a </span>
<Span> B </span>
<Span> c </span>
</Div>
1. Incorrect Method: The jquery object array cannot be obtained using the [] method, as shown below:
Copy codeThe Code is as follows:
$ (Function (){
Var div_span = $ ("# div1 span ");
For (var I = 0; I <div_span.length; I ++ ){
Div_span.[ I #.html (I );
}
});
This is invalid.
2. YesUsing jquery's eq () methodTo select:
Copy codeThe Code is as follows:
For (var I = 0; I <div_span.length; I ++ ){
Div_span.eq( I ).html (I );
}
3. YesUse the each () method to traverse:
Copy codeThe Code is as follows:
$ (Function (){
Var div_span = $ ("# div1 span ");
Var I = 0;
Div_span.each (function (){
Certificate (this).html (I );
I ++;
});
});
During each () traversal, if $ (this) is used to obtain the jquery object, if this is used directly, the DOM object is obtained.
4DOM object array obtained by. js Code only, You can use [] to obtain array elements.
The next three methods are correct. The first is wrong. Put him in the first place because we must emphasize that we cannot make the same mistake again in the future. Let's take a closer look.