首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jquery 如何设置多个checkbox选中

2013-07-08 
jquery 怎么设置多个checkbox选中input typecheckbox idcheckid1 nameimage.datavalue value1

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"/>周六

热点排行