Radio defaultCheckedProperty

Radio 对象参考手册Radio Object

Definition and Usage

The defaultChecked property returns the default value of the checked attribute.

If the default state of the radio button is checked, it returns true; otherwise, it returns false.

Syntax

radioObject.defaultChecked


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the defaultChecked property.


Example

Example

Detect whether the "Blue" option is selected by default:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("blue").defaultChecked;
    alert(x);
}
</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" checked="checked">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="displayResult()">Is blue selected by default?</button>

</body>
</html>

Try it Yourself »


Radio 对象参考手册Radio Object Other Extensions