傳統選取取消程式碼如下:
[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中文網其他相關文章!