Home  >  Article  >  Web Front-end  >  How to solve the problem that the checkbox fails after being selected again?

How to solve the problem that the checkbox fails after being selected again?

零下一度
零下一度Original
2017-07-18 15:36:141743browse

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(&#39;checked&#39;,false);</span>  
        };  
        var btn_submit = function(){  
            <span style="color:#ff0000;">$("#checkbox").attr(&#39;checked&#39;,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:

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

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn