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

How to cancel radio in jquery

青灯夜游
青灯夜游Original
2022-03-28 15:21:342910browse

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>
  • Use prop ()Set the checked attribute value

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

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!

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