Judgment method: 1. Use the "$(checkbox element).prop('checked')" statement. If true is returned, it is selected, if false is returned, it is not selected; 2. Use "$(checkbox element) Box element).is(':checked')" statement, if true is returned, it is checked, if false is returned, it is not checked.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery determines whether the check box is checked
Method 1: Use prop('checked')
If true is returned, it is selected, if false is returned, it is not selected
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var isChecked = $('#cbx').prop('checked'); alert(isChecked); }); }); </script> </head> <body> <input type="checkbox" id="cbx" /><label for="cbx">点我</label><br /><br /> <button>判断复选框是否被选中</button> </body> </html>
Method 2: Use is(': checked')
If true is returned, it is checked, if false is returned, it is not checked
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var isChecked = $('#cbx').is(':checked'); alert(isChecked); }); }); </script> </head> <body> <input type="checkbox" id="cbx" /><label for="cbx">点我</label><br /><br /> <button>判断复选框是否被选中</button> </body> </html>
Related video tutorial recommendations: jQuery Tutorial(Video)
The above is the detailed content of How to determine whether a checkbox is selected in jquery. For more information, please follow other related articles on the PHP Chinese website!