日期:2014-05-16  浏览次数:20329 次

jquery 怎么设置多个checkbox选中

<input type="checkbox" id="checkid1" name="image.datavalue" value="1"/>周一
<input type="checkbox" id="checkid2" name="image.datavalue" value="2"/>周二
<input type="checkbox" id="checkid3" name="image.datavalue" value="3"/>周三
<input type="checkbox" id="checkid4" name="image.datavalue" value="4"/>周四
<input type="checkbox" id="checkid5" name="image.datavalue" value="5"/>周五
<input type="checkbox" id="checkid6" name="image.datavalue" value="6"/>周六



问一下,我选择周二,周五,周六  我保存的时候数据就是 2,5,6

现在 我点击修改,需要将 原有的数据填充进去,将周二,周五,周六 选中
Jquery或者JS 请问怎么做?  
    

------解决方案--------------------

$("input [name='image.datavalue']").attr("checked",true);

------解决方案--------------------

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("a").click(function(){
$(":checkbox").each(function(){
if($(this).val()==2
------解决方案--------------------
$(this).val()==5
------解决方案--------------------
$(this).val()==6){
$(this).attr("checked",true);
}
});
});
})
</script>
<a href="#">修改</a>
<input type="checkbox" id="checkid1" name="image.datavalue" value="1"/>周一
<input type="checkbox" id="checkid2" name="image.datavalue" value="2"/>周二
<input type="checkbox" id="checkid3" name="image.datavalue" value="3"/>周三
<input type="checkbox" id="checkid4" name="image.datavalue" value="4"/>周四
<input type="checkbox" id="checkid5" name="image.datavalue" value="5"/>周五
<input type="checkbox" id="checkid6" name="image.datavalue" value="6"/>周六