我编写了一个函数来检查页面上所有的复选框输入,并将“选中的”输入放入一个数组中。被检查的值是正确的,但是我也得到了这些"dedup: function,contains: function“值。为什么?
下面是我的函数:
var custTreatments = [];
function Checkform() {
$(':checkbox:checked').each(function(){
custTreatments.push($(this).val());
return custTreatments;
});
}
Checkform();
HTML非常简单:
<input type="checkbox" value="item1" />item1
<input type="checkbox" value="item2" />item2
<input type="checkbox" value="item3" />item3
谢谢!
发布于 2014-01-17 00:49:11
将js实现编辑为:
var custTreatments = [];
function Checkform() {
$('[type=checkbox]:checked').each(function(){
custTreatments.push($(this).val());
return custTreatments;
});
}
Checkform();
更新
我检查过了。我犯了一个错。T_T
checkbox $(“:
”)等同于$( "type=checkbox“)
您的代码似乎工作得很好。
在http://jsfiddle.net/B274h/1/上进行测试
你能再复制一次吗?
https://stackoverflow.com/questions/21175732
复制