Radio checked 屬性
Radio 對(duì)象定義和用法
checked 屬性可設(shè)置或返回某個(gè)單選按鈕是否被選中。
語法
設(shè)置 checked 屬性:
radioObject.checked=true|false
返回 checked 屬性:
radioObject.checked
瀏覽器支持
所有主要瀏覽器都支持 checked 屬性
實(shí)例
實(shí)例
下面的例子可對(duì)一個(gè)單選按鈕進(jìn)行選定和不選定:
<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>
嘗試一下 ?
Radio 對(duì)象
更多建議: