ID is a unique id of some elements on the html page, including div, input, iframe, etc, the following describes how to use jquery to obtain the id value. For more information, see.
The Code is as follows: |
Copy code |
<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:
The Code is as follows: |
Copy code |
<Table> <Tr> <td> Header 1 </td> </tr> <Tr> <td> Value 1 </td> </tr> <Tr> <td> Value 2 </td> </tr> </Table>
|
JQuery code:
The Code is as follows: |
Copy code |
$ ("Tr: eq (1 )")
|
Result:
The Code is as follows: |
Copy code |
[<Tr> <td> Value 1 </td> </tr>] |
Obtain the values of different IDs
The Code is as follows: |
Copy code |
<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"> & nbsp; </span> </Span> <Span id = "0_2"> bbb, <Span group_id = "0_2" class = "icon_close"> & nbsp; </span> </Span> <Span id = "0_3"> ccc, <Span group_id = "0_3" class = "icon_close"> & nbsp; </span> </Span> <Span id = "0_4"> ddd, <Span group_id = "0_4" class = "icon_close"> & nbsp; </span> </Span> <Span id = "0_5"> eee, <Span group_id = "0_5" class = "icon_close"> & nbsp; </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:
The Code is as follows: |
Copy code |
$ ("# Txt"). attr ("value", ''); // clear the content $ ("# Txt"). attr ("value", '11'); // fill in the content |
Multiple selection box checkbox:
The Code is as follows: |
Copy code |
$ ("# 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. |