[jquery] checkbox 全选失效问题解决
<script type="text/javascript">
$(function(){
$(".select-children-all").on('click', function(){
var checkList = $(this).parent().parent().next().find('[type="checkbox"]');
if (checkList.first().attr('checked')) {
checkList.attr('checked', false);
} else {
checkList.attr('checked', true);
}
})
})
</script>
使用attr属性,第二次全选失效。改正如下:
<script type="text/javascript">
$(function(){
$(".select-children-all").on('click', function(){
var checkList = $(this).parent().parent().next().find('[type="checkbox"]');
if (checkList.first().prop('checked')) {
checkList.prop('checked', false);
} else {
checkList.prop('checked', true);
}
})
})
</script>
版权声明:本文为李维亮博主的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:http://www.liweiliang.com/174.html
评论已关闭