jquery的全选和反选案例网上一大把,今天写了一个,发现有兼容性的问题,找了好久才知道低版本的jquery库支持attr("checked")=="checked"的写法,而不支持attr("checked")==true的写法。以下这段代码解决了兼容这个问题:
<!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>jquery全选和反选(兼容)</title>
<script src="jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
function flowCheck(thisClass){
// $(thisClass).attr("checked")=="checked"或$(thisClass).attr("checked")==true 是为了兼容不同版本的jquery库
if($(thisClass).attr("checked")=="checked"||$(thisClass).attr("checked")==true){
$(".contorlBox,.flowCheckbox").attr("checked","checked");
}else{
$(".contorlBox,.flowCheckbox").attr("checked",false);
}
}
</script>
<input type="checkbox" class="contorlBox" onclick="flowCheck(this)" />全选<br/>
<input type="checkbox" value="597" class="flowCheckbox" /> PHP学习<br/>
<input type="checkbox" value="597" class="flowCheckbox" /> PHP源码<br/>
<input type="checkbox" value="597" class="flowCheckbox" /> JS学习<br/>
<input type="checkbox" value="597" class="flowCheckbox" /> 代潇瑞博客<br/>
<input type="checkbox" class="contorlBox" onclick="flowCheck(this)" />全选<br/>
</body>
</html>
虽然不难,但是有时候兼容真的很难去处理,使用这个jquery范例是个不错的选择。
文章出自:https://www.daixiaorui.com/read/101.html 本站所有文章,除注明出处外皆为原创,转载请注明本文地址,版权所有。
蛋仔派对无限蛋币http://www.wzryzs.com/
666
666
很好的方法值得推荐
gg修改器https://www.guiyangtax.com/ 葫芦侠http://www.booj.net/ 八门神器http://www.tusovok.net/
gg修改器https://www.guiyangtax.com/ 葫芦侠http://www.booj.net/ 八门神器http://www.tusovok.net/