CodeLab
Show Output
 
xxxxxxxxxx
24
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>Check the Status of Checkboxes</title>
6
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
7
<script>
8
    $(document).ready(function(){
9
        $('input[type="checkbox"]').click(function(){
10
            if($(this).prop("checked") == true){
11
                $("#result").html("Checkbox is checked.");
12
            }
13
            else if($(this).prop("checked") == false){
14
                $("#result").html("Checkbox is unchecked.");
15
            }
16
        });
17
    });
18
</script>
19
</head>
20
<body>
21
    <p><input type="checkbox"> Check or uncheck the checkbox to get the status.</p>
22
    <div id="result" style="background: yellow;"></div>
23
</body>
24
</html>
 

在微博、微信、公众号、小程序分享此示例。 如果您觉得有帮助,请给我们一个赞。