The traditional selection and cancellation code is as follows:
[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>
//Problem point
The initial state check box is not all selected,
Click to select all The button calls the checkAll method,
realizes the selection of all,
and then clicks the “Deselect All” button,
realizes the deselection of all,
Then click the Select All button again,
but the result is not all selected,
No response will occur if you click it repeatedly.
demo:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title><script src="js/jquery-1.11.3.min.js?1.1.11"></script><script>$(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); } }) })</script></head><body><input type="checkbox" name="checkbox" id="">乒乓球<input type="checkbox" name="checkbox" id="">羽毛球<input type="checkbox" name="checkbox" id="">足球<input type="checkbox" name="checkbox" id="">篮球<input type="checkbox" name="checkbox" id="">排球<br><input type="button" value="全选" id="allchoose"><input type="button" value="全不选" id="allnochoose"><input type="button" value="反选" id="choose"><input type="submit" value="提交" id="submit"></body></html>
The above is the detailed content of How to solve the problem that the checkbox fails after being selected again?. For more information, please follow other related articles on the PHP Chinese website!