admin管理员组文章数量:1023213
I have around 9 checkboxes with different rel values. How can I get the all the rel values of checked check boxes in an array or as csv using jQuery?
<input type="checkbox" name="item" rel="WVSEUPU" />
I have around 9 checkboxes with different rel values. How can I get the all the rel values of checked check boxes in an array or as csv using jQuery?
<input type="checkbox" name="item" rel="WVSEUPU" />
Share
Improve this question
edited Feb 12, 2017 at 20:05
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Jul 18, 2011 at 8:37
esafwanesafwan
18.1k35 gold badges110 silver badges170 bronze badges
1
- 2 input elements don't have a rel attribute, either use a standard attribute (e.g. class) or an HTML5 data- attribute. – RobG Commented Jul 18, 2011 at 9:27
2 Answers
Reset to default 4var relArr=[];
$("input[type='checkbox']:checked").each(function(){
relArr.push($(this).attr('rel'));
});
here is the working fiddle http://jsfiddle/7zSRQ/
You could do:
var rels = [];
$('input[type="checkbox"]:checked').each(function(){
var rel = $(this).attr('rel');
rels.push(rel);
});
//rels is an array you could use rels.join(',') to join the array.
I have around 9 checkboxes with different rel values. How can I get the all the rel values of checked check boxes in an array or as csv using jQuery?
<input type="checkbox" name="item" rel="WVSEUPU" />
I have around 9 checkboxes with different rel values. How can I get the all the rel values of checked check boxes in an array or as csv using jQuery?
<input type="checkbox" name="item" rel="WVSEUPU" />
Share
Improve this question
edited Feb 12, 2017 at 20:05
marc_s
757k184 gold badges1.4k silver badges1.5k bronze badges
asked Jul 18, 2011 at 8:37
esafwanesafwan
18.1k35 gold badges110 silver badges170 bronze badges
1
- 2 input elements don't have a rel attribute, either use a standard attribute (e.g. class) or an HTML5 data- attribute. – RobG Commented Jul 18, 2011 at 9:27
2 Answers
Reset to default 4var relArr=[];
$("input[type='checkbox']:checked").each(function(){
relArr.push($(this).attr('rel'));
});
here is the working fiddle http://jsfiddle/7zSRQ/
You could do:
var rels = [];
$('input[type="checkbox"]:checked').each(function(){
var rel = $(this).attr('rel');
rels.push(rel);
});
//rels is an array you could use rels.join(',') to join the array.
版权声明:本文标题:javascript - Get the rel attribute value of all checked inputs as an array or csv using jQuery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745556581a2155912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论