Home > Web Front-end > Front-end Q&A > How to remove the selected state of radio radio button in jquery

How to remove the selected state of radio radio button in jquery

青灯夜游
Release: 2022-06-09 18:36:14
Original
7023 people have browsed it

3 methods: 1. Use removeAttr() to remove the checked attribute of the radio box, the syntax is "radio button object.removeAttr("checked");". 2. Use attr() to set the value of the checked attribute to false, the syntax is "object.attr("checked",false)"; 3. Use prop() to set the value of the checked attribute to false, the syntax is "object.prop( "checked",false)".

How to remove the selected state of radio radio button in jquery

The operating environment of this tutorial: windows7 system, jquery3.6.0 version, Dell G3 computer.

3 ways to remove the selected status of radio radio button in jquery

Method 1: Use removeAttr()

The selected state of the radio radio button is controlled by the checked attribute. Just use removeAttr() to remove this attribute.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<script src="js/jquery.min.js"></script>
		<script>
			$(document).ready(function(){
				$("button").click(function(){
					$("input").removeAttr("checked");
				});
			});
		</script>
		<style>
			p{
				width: 200px;
				height: 100px;
				border: 1px solid #AFEEEE;
				background-color: #AFEEEE;
			}
		</style>
	</head>
	<body>

		<input type="radio" name="radio1" value="value1" />选项1<br>
		<input type="radio" name="radio1" value="value2" checked />选项2<br>
		<input type="radio" name="radio1" value="value3" />选项3<br><br>
		<button>去掉radio选中状态</button>

	</body>
</html>
Copy after login

How to remove the selected state of radio radio button in jquery

Method 2: Use attr()

You can also use attr() to set the checked attribute of the radio radio button Use a value of false to deselect the radio.

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

How to remove the selected state of radio radio button in jquery

Method 3: Use prop()

You can also use prop() to set the checked attribute of the radio radio button is false value.

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

How to remove the selected state of radio radio button in jquery

[Recommended learning: jQuery video tutorial, web front-end video

The above is the detailed content of How to remove the selected state of radio radio button 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