传统选中取消代码如下:
[html] view plain copy print? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script> </head> <body> <input type="checkbox" name="checkbox" id="checkbox" > <input type="button" onclick="btn_submit();" name="" id="btn_submit" value="选中"> <input type="button" onclick="btn_cancel();" id="btn_cancel" value="取消选中"> </body> <script> var btn_cancel = function(){ <span style="color:#ff0000;">$("#checkbox").attr('checked',false);</span> }; var btn_submit = function(){ <span style="color:#ff0000;">$("#checkbox").attr('checked',true);</span> }; </script> </html>
//问题点
初始状态复选框没有全选,
点击全选按钮调用checkAll方法,
实现了全选,
然后点击全不选按钮,
实现了全不选,
然后再次点击全选按钮,
结果却木有全选,
再反复点击木有任何反应。
demo:
76c82f278ac045591c9159d381de2c579fd01892b579bba0c343404bcccd70fb93f0f5c25f18dab9d176bd4f6de5d30ea80eb7cbb6fff8b0ff70bae37074b813b2386ffb911b14667cb8f0f91ea547a7Title6e916e0f7d1e588d4f442bf645aedb2f6384a94401dd3513192f74c325564aea2cacc6d41bbb37262a98f745aa00fbf03f1c4e4b6b16bbbd69b2ee476dc4f83a$(function () { $("#allchoose").click(function () { $(":checkbox").prop("checked",true); }) $("#allnochoose").click(function () {if ($(":checkbox").is(":checked")){ $(":checkbox").attr("checked",false); } }) $("#choose").click(function () {if($(":checkbox").is(":checked")){ $(":checkbox").attr("checked",false); }else{ $(":checkbox").prop("checked",true); } }) })2cacc6d41bbb37262a98f745aa00fbf09c3bca370b5104690d9ef395f2c5f8d16c04bd5ca3fcae76e30b72ad730ca86d05f88359cedaf04b59ecc6462ae643a3乒乓球05f88359cedaf04b59ecc6462ae643a3羽毛球05f88359cedaf04b59ecc6462ae643a3足球05f88359cedaf04b59ecc6462ae643a3篮球05f88359cedaf04b59ecc6462ae643a3排球0c6dc11e160d3b678d68754cc175188ac298a9150f2032ba9c3fe765dfee4fa19638d8e6fd0d8d8d915cec792be9f6422f4258eeae05fe136e53d11f74f1bc52215346cc9e1a329ee20621ddbf63cae836cc49f0c466276486e50c850b7e495673a6ac4ed44ffec12cee46588e518a5e
以上是checkbox选中后再次选中失效该如何解决?的详细内容。更多信息请关注PHP中文网其他相关文章!