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)".
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>
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); }); });
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); }); });
[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!