admin管理员组文章数量:1417724
How to get the values of Dynamically generated CheckBoxes using jquery
for(i=startAt;i<limit;i++)
{
var str = '<tr>'+
'<td width="48" align="center"><input class="A" type="checkbox" name="checkbox" value='+ local[i]['_id'] +'></td>'+
'<td width="270" >' + local[i]['_id'] +'</td>'+
'<td width="883" class="alignRt">'+local[i]['count']+'</td>'+
'</tr>'
$("#tableBody").append(str);
}
using this I am able to get the total checkboxes at runtime
$(document).on('click', '.A', function(){
var n = $("input:checked.A").length;
console.log(n)
But I want to get the values too.
How can I do that ?
How to get the values of Dynamically generated CheckBoxes using jquery
for(i=startAt;i<limit;i++)
{
var str = '<tr>'+
'<td width="48" align="center"><input class="A" type="checkbox" name="checkbox" value='+ local[i]['_id'] +'></td>'+
'<td width="270" >' + local[i]['_id'] +'</td>'+
'<td width="883" class="alignRt">'+local[i]['count']+'</td>'+
'</tr>'
$("#tableBody").append(str);
}
using this I am able to get the total checkboxes at runtime
$(document).on('click', '.A', function(){
var n = $("input:checked.A").length;
console.log(n)
But I want to get the values too.
How can I do that ?
Share Improve this question edited Sep 23, 2015 at 19:51 user784540 asked Jun 13, 2013 at 13:21 Alok AgarwalAlok Agarwal 3,0993 gold badges25 silver badges34 bronze badges 5- 2 You are generating invalid HTML, ids must be unique – Quentin Commented Jun 13, 2013 at 13:22
- 2 You should learn how to use the label element – Quentin Commented Jun 13, 2013 at 13:24
- if i remove id than too i want to get the values of all generated checkboxes as soon as they get clicked @Quentin – Alok Agarwal Commented Jun 13, 2013 at 13:27
-
use
.class
instead. – Omar Commented Jun 13, 2013 at 13:27 - @ Quentin i have updated the code i want the values at runtime – Alok Agarwal Commented Jun 13, 2013 at 13:30
4 Answers
Reset to default 5Use the :checked
selector
jQuery('.A:checked')
You can then loop over the elements to get all their values.
$(document).on('click', '.A', function(){
var n = $( "input:checked.A" ).length;
var arr=[]
for(i=0;i<n;++i){
arr.push($($( "input:checked.A" )[i]).val())
}
alert(arr)
});
You can get checked checkboxes using:
$("#tableBody").find("input:checked");
It returns a list of checked checkboxes
use JQuery's $('#CheckboxID').val()
本文标签: javascriptHow to get dynamically generated check box valuesStack Overflow
版权声明:本文标题:javascript - How to get dynamically generated check box values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745264000a2650485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论