Home > Web Front-end > Front-end Q&A > How to cancel radio in jquery

How to cancel radio in jquery

青灯夜游
Release: 2022-03-28 15:21:34
Original
2881 people have browsed it

Jquery method to cancel radio: 1. Use the attr() function, the syntax "$("input").attr("checked",false);"; 2. Use the prop() function, the syntax " $("input").prop("checked",false);".

How to cancel radio in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery method to cancel radio

In jquery, you only need to set the checked attribute of the radio radio button to a false value to cancel it radio is selected.

There are two ways to set attribute values:

  • attr()

  • prop()

Example:

  • Use attr() to set the checked attribute value

<!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() {
					$("input").attr("checked",false);
				});
			});
		</script>
	</head>
	<body>
		<div>
			<input type="radio" name="1" value="1" id="rdoYear" checked>本年<br />
			<input type="radio" name="1" value="2" id="rdoMonth">本月<br />
			<input type="radio" name="1" value="3" id="rdoDay">本日<br />
		</div>
		<button>取消选中</button>

	</body>
</html>
Copy after login
  • Use prop ()Set the checked attribute value

<script>
	$(document).ready(function() {
		$("button").click(function() {
			$("input").prop("checked",false);
		});
	});
Copy after login

The effect achieved is the same

How to cancel radio in jquery

[Recommended learning: jQuery Video tutorialweb front-end video

The above is the detailed content of How to cancel radio 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