jquery操作checkbox火狐下第二次无法勾选问题

原来的代码:

$('#checkAll').click(function(){
                var current = $(this)
                $('.checkbox').each(function(){
                    debugger;
                    if(current.is(':checked')) {
                        $(this).attr('checked', true);
                    } else {
                        $(this).attr('checked', false);
                    }
                });
            })

这样在firefox和chrome浏览器下第二次勾选时,属性改变了,页面显示没有改变。经百度发现是JQUERY版本的问题。

$('#checkAll').click(function(){
                var current = $(this)
                $('.checkbox').each(function(){
                    debugger;
               	 if(current.is(':checked')) {
               		 $(this).prop('checked', true);
               	 } else {
               		 $(this).prop('checked', false);
               	 }
                });
            })

  把attr换成prop即可解决。

posted @ 2014-09-23 10:30  b13272012771  阅读(195)  评论(0编辑  收藏  举报