我有一个类似的数组
var values = ['1','3','4','5'];
我有复选框列表
<div id='list'>
<input type='checkbox' value='1' />
<input type='checkbox' value='2' />
<input type='checkbox' value='3' />
<input type='checkbox' value='4' />
<input type='checkbox' value='5' />
<input type='checkbox' value='6' />
<input type='checkbox' value='7' />
<input type='checkbox' value='8' />
<input type='checkbox' value='9' />
<input type='checkbox' value='10' />
</div>
现在我想选择其值位于数组值内的复选框。我已经这样做了
for(var i = 0; i < values.length; i++)
$("#list [value=" + values[i] + "]").attr("checked", "checked");
它工作正常,但我可以在没有 for 循环的情况下完成它吗?
预先感谢各位帮助者。
Try
$("#list").find('[value=' + values.join('], [value=') + ']').prop("checked", true);
Demo: Fiddle http://jsfiddle.net/arunpjohny/Z5vZ8/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)