Home > Article > Web Front-end > Summary of how to get id value in jquery
Some elements in the html page can have a unique id for this page. Here is a summary of how to use jquery to obtain the id value. I hope it will be helpful to everyone learning jquery.
<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)
Matches an element with a given index value
Matches a single element by its index.
Return value
Element
Parameters
index (Number): Count from 0
Example
Find the second row
Get the value of different id
<script src="js/jquery.js"></script> <script type="text/javascript"> <!-- $(document).ready(function(){ var len = $("#group span").size();//获取span标签的个数 var arr = []; for(var index = 0; index < len-1; index++){//创建一个数字数组 arr[index] = index; } $.each(arr, function(i){//循环得到不同的id的值 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 code:
$("#txt").attr("value",'');//清空内容 $("#txt").attr("value",'11');//填充内容
Multiple selection box checkbox code:
$("#chk1").attr("checked",'');//不打勾 $("#chk2").attr("checked",true);//打勾 if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
The above is the detailed content of Summary of how to get id value in jquery. For more information, please follow other related articles on the PHP Chinese website!