我有一个数组在js中包含一些名称的复选框,我想设置检查。 问题是我不能做正确,我不知道为什么我错了 这是我的代码多选复选框设置检查html
var array = ['one','two word','three'];
for(var i = 0; i < array.length;i++)
$(':checkbox[value="'+array[i]+'"]').prop('checked', true);
有了这个HTML
<input type="checkbox" name="one[]" value="two word">
<input type="checkbox" name="one[]" value="four">
<input type="checkbox" name="one[]" value="one">
有了这个代码我复选框保持uncheked,可有人告诉我为什么?
问题仍然存在,这是复选框 [prevObject的控制台日志:n.fn .init [1],context:document,selector:“:checkbox [value =”Trieste“]]] context:documentlength:0prevObject:n.fn.init [1] selector:”:checkbox [value =“one”] “__proto__:n [0] – cristianbregant
是这样吗?你可以在代码片段中运行代码吗? –
是的,但在这一点上,我认为在别的地方可能会有问题。我现在要看看问题:D谢谢! – cristianbregant