第一次点击全选能成功,但是第二次全选不了,换了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>
下面的checked设置也应该用prop();