Copy codeThe Code is as follows:
<Div id = "product_shift_out _ {m}"> </div>
<Script language = "JavaScript" type = "text/javascript">
$ (Document). ready (function (){
Name = $ ('div '). eq (0). attr ('id ');
Alert (name)
});
</Script>
Eq (0) is the first jq element...
Eq (index)
Matches an element with a given index value.
Matches a single element by its index.
Return Value
Element
Parameters
Index (Number): starts from 0.
Example
Find the second row
HTML code:
Copy codeThe Code is as follows:
<Table>
<Tr> <td> Header 1 </td> </tr>
<Tr> <td> Value 1 </td> </tr>
<Tr> <td> Value 2 </td> </tr>
</Table>
JQuery code:
Copy codeThe Code is as follows:
$ ("Tr: eq (1 )")
Result:
Copy codeThe Code is as follows:
[<Tr> <td> Value 1 </td> </tr>]
Obtain the values of different IDs
Copy codeThe Code is as follows:
<Script src = "js/jquery. js"> </script>
<Script type = "text/javascript">
<! --
$ (Document). ready (function (){
Var len = $ ("# group span"). size (); // obtain the number of span tags
Var arr = [];
For (var index = 0; index <len-1; index ++) {// create an array of numbers
Arr [index] = index;
}
$. Each (arr, function (I) {// cyclically obtain values of different IDs
Var idValue = $ ("# group span"). eq (I). attr ("id ");
If (idValue! = ''){
Alert (idValue );
}
});
});
// -->
</Script>
<Span id = "group">
<Span id = "0_1"> aaa,
<Span group_id = "0_1" class = "icon_close"> </span>
</Span>
<Span id = "0_2"> bbb,
<Span group_id = "0_2" class = "icon_close"> </span>
</Span>
<Span id = "0_3"> ccc,
<Span group_id = "0_3" class = "icon_close"> </span>
</Span>
<Span id = "0_4"> ddd,
<Span group_id = "0_4" class = "icon_close"> </span>
</Span>
<Span id = "0_5"> eee,
<Span group_id = "0_5" class = "icon_close"> </span>
</Span>
</Span>
In this way, you will get all the IDs you want:
0_1
0_2
0_3
0_4
0_5
Text Box, text area:
Copy codeThe Code is as follows:
$ ("# Txt"). attr ("value", ''); // clear the content
$ ("# Txt"). attr ("value", '11'); // fill in the content
Multiple selection box checkbox:
Copy codeThe Code is as follows:
$ ("# Chk1"). attr ("checked", ''); // do not check
$ ("# Chk2"). attr ("checked", true); // check
If ($ ("# chk1"). attr ('checked') = undefined) // you can check whether the checked has been checked.