checked
收藏:0
阅读:19
Radio checked 属性
定义和用法
checked 属性可设置或返回某个单选按钮是否被选中。
语法
设置 checked 属性:
radioObject.checked=true|false
返回 checked 属性:
radioObject.checked
浏览器支持
所有主要浏览器都支持 checked 属性
实例
下面的例子可对一个单选按钮进行选定和不选定:
<html>
<head>
<script>
function check()
{
document.getElementById("red").checked=true
}
function uncheck()
{
document.getElementById("red").checked=false
}
</script>
</head>
<body>
<form>
What 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()">Check "Red"</button>
<button type="button" onclick="uncheck()">Uncheck "Red"</button>
</body>
</html>
<head>
<script>
function check()
{
document.getElementById("red").checked=true
}
function uncheck()
{
document.getElementById("red").checked=false
}
</script>
</head>
<body>
<form>
What 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()">Check "Red"</button>
<button type="button" onclick="uncheck()">Uncheck "Red"</button>
</body>
</html>