开发者社区 问答 正文

jquery全选效果第一次可执行,之后无法执行?

demo在这https://jsfiddle.net/6wsa3g2y/点击预览
很奇怪,第一次可以执行,之后就无法执行了,不知怎么回事?

展开
收起
小旋风柴进 2016-05-30 09:22:10 1676 分享 版权
1 条回答
写回答
取消 提交回答
  • 是 prop 不是 attr..还有楼主代码需要优化下。。

    $(function(){
    $(function(){
             $("#checkAll").on("click",function(){
                 $("input[name='subBox']").prop("checked",this.checked);
             });
            
            var subBox=$("input[name='subBox']");
            subBox.on('click',function(){
                $("#checkAll").prop("checked",subBox.length == $("input[name='subBox']:checked").length ?true :false);
            });
    
         });
    
    2019-07-17 19:18:59
    赞同 展开评论
问答分类:
问答标签:
问答地址: