Home > Web Front-end > JS Tutorial > How to determine whether a checkbox is selected in jquery

How to determine whether a checkbox is selected in jquery

青灯夜游
Release: 2021-11-25 18:21:01
Original
10155 people have browsed it

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.

How to determine whether a checkbox is selected in jquery

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 = $(&#39;#cbx&#39;).prop(&#39;checked&#39;);
					alert(isChecked);
				});
			});
			</script>
	</head>
	<body>

		<input type="checkbox" id="cbx" /><label for="cbx">点我</label><br /><br />
		<button>判断复选框是否被选中</button>

	</body>
</html>
Copy after login

How to determine whether a checkbox is selected in jquery

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 = $(&#39;#cbx&#39;).is(&#39;:checked&#39;);
					alert(isChecked);
				});
			});
			</script>
	</head>
	<body>

		<input type="checkbox" id="cbx" /><label for="cbx">点我</label><br /><br />
		<button>判断复选框是否被选中</button>

	</body>
</html>
Copy after login

How to determine whether a checkbox is selected in jquery

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template