您的位置:首页 > 其它

遍历多个checkbox并获取值

2016-06-28 11:47 295 查看
<input type="checkbox" name="productTag"  value="1" >
<input type="checkbox" name="productTag"  value="2" >
<input type="checkbox" name="productTag"  value="3" >
<input type="checkbox" name="productTag"  value="4" >
</pre><pre code_snippet_id="1733203" snippet_file_name="blog_20160628_1_8107507" name="code" class="html">var s = $("input[name='productTag']");
s.each(function(i) {
$(this).click(function(){
var tag="";
$(':checkbox[name=productTag]:checked').each(function(){
tag+=$(this).val()+",";

});

if(tag!=""){
$("#tag").val(tag.substring(0,tag.length-1));
}
else{
$("#tag").val("");
}
});
});





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: