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 to take the first JQ element ...
EQ (Index)
An element that matches a given index value
--------------------------------------------------------------------------------
Matches a single element by its index.
return value
Element
Parameters
Index (number): Counting starting from 0
Example
Find 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)")
|
Results:
The code is as follows |
Copy Code |
[<tr><td>value 1</td></tr>] |
Get values for 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 ();//Get the number of span labels var arr = []; for (var index = 0; index < len-1; index++) {//Create a numeric array Arr[index] = index; } $.each (arr, function (i) {//loop to get different ID values 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> This 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", "");/empty content $ ("#txt"). attr ("value", ' 11 ');//fill content |
Multi-selection box checkbox:
code is as follows |
copy code |
$ ("#chk1"). attr ("Checked", "");/no tick $ ("#chk2"). attr ("Checked", true);/tick if ($ ("#chk1"). attr (' checked ') ==undefined) /Determine if you have ticked |