Radio checkedProperty

Radio 对象参考手册Radio Object

Definition and Usage

The checked property sets or returns whether a radio button is checked.

Syntax

Set the checked property:

radioObject.checked=true|false

Return the checked property:

radioObject.checked


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the checked property


Examples

Examples

The following example can select and deselect a radio button:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function check(){
    document.getElementById("red").checked=true
}
function uncheck(){
    document.getElementById("red").checked=false
}
</script>
</head>
<body>

<form>
Which color do you prefer?<br>
<input type="radio" name="colors" id="red">Red<br>
<input type="radio" name="colors" id="blue">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="check()">Select "Red"</button>
<button type="button" onclick="uncheck()">Deselect "Red"</button>
    
</body>
</html>

Try it Yourself »


Radio 对象参考手册Radio Object Other Extensions