This article provides three ways to deselect radio, as shown in the following code example:
This article relies on jquery, the first of which is implemented using jquery, and the third Way is based on JS and Dom.
Copy Code code as follows:
<! DOCTYPE html>
<title> radio button unchecked three ways </title>
<script type= "Text/javascript" src= "Http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js" >
</script>
<script type= "Text/javascript" >
$ (function () {
//
var $browsers = $ ("input[name=browser]");
var $cancel = $ ("#cancel");
var $byhide = $ ("#byhide");
var $remove = $ ("#remove");
//
$cancel. Click (function (e) {
To remove a property, either way
$browsers. Removeattr ("checked");
$browsers. attr ("checked", false);
});
//
$byhide. Click (function (e) {
Switch to a hidden field, both of which can be
$ ("#hidebrowser"). attr ("Checked", true);
$ ("#hidebrowser"). attr ("Checked", "checked");
});
//
$remove. Click (function (e) {
Go directly to the DOM element, remove the attribute
If you don't use jquery, you can migrate this way
var checkedbrowser=document.getelementsbyname ("browser");
/*
$.each (Checkedbrowser, function (i,v) {
v.checked = false;
V.removeattribute ("checked");
});
*/
//
var len = checkedbrowser.length;
var i = 0;
for (; i < Len; i++) {
You must first assign a value of false and then remove the property
checkedbrowser[i].checked = false;
Do not remove properties can also
Checkedbrowser[i].removeattribute ("checked");
}
});
});
</script>
<body>
<p> which browser do you prefer? </p>
<form>
<input style= "Display:none id=" Hidebrowser "type=" Radio "name=" browser "value=" ">
<input type= "Radio" name= "browser" value= "Internet Explorer" >internet explorer<br
<input type= "Radio" name= "browser" value= "Firefox" >firefox<br/>
<input type= "Radio" name= "browser" value= "Netscape" >netscape<br/>
<input type= "Radio" name= "browser" value= "Opera" >opera<br/>
<br/>
<input type= "button" id= "Cancel" value= "uncheck the Way 1" size= ">
<input type= "button" id= "Byhide" value= "uncheck the Way 2" size= ">
<input type= "button" id= "Remove" value= "uncheck the way 3" size= ">
</form>
</body>