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);".
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
[Recommended learning: jQuery Video tutorial、web 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!