prop兼容

第一次点击全选能成功,但是第二次全选不了,换了jQuery版本,要么是谷歌不行,要么IE8不行,
哪个版本才能一起兼容谷歌和IE8,或者有没有什么其他方式实现全选

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
    <script>
    $(function(){
        $("input[id='cbSelAll']").click(function(){
            //alert($(this).prop("checked"));
            if($(this).prop("checked"))
            {
                //alert("全选");
                $("input[id*='cbSel']").attr("checked","checked");
            }
            else
            {
                //alert("取消");
                $("input[id*='cbSel']").removeAttr("checked");
            }
        })    
    })
    </script>
</head>

<body>
全选<input type="checkbox" id="cbSelAll" /><br />
<input type="checkbox" id="cbSel1"  />
<input type="checkbox" id="cbSel2" />
<input type="checkbox" id="cbSel3" />
</body>
</html>
阅读 3.2k
1 个回答

下面的checked设置也应该用prop();

//全选
$("input[id*='cbSel']").prop("checked",true);
//取消
$("input[id*='cbSel']").prop("checked",false);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题