天天看點

Radio checked 屬性

Radio checked 屬性

Radio 對象

checked 屬性可設定或傳回某個單選按鈕是否被選中。

設定 checked 屬性:

radioObject.checked=true|false

傳回 checked 屬性:

radioObject.checked

Radio checked 屬性
Radio checked 屬性
Radio checked 屬性
Radio checked 屬性
Radio checked 屬性

所有主要浏覽器都支援 checked 屬性

下面的例子可對一個單選按鈕進行標明和不標明:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>菜鳥教程(runoob.com)</title>

<script>

function check(){

    document.getElementById("red").checked=true

}

function uncheck(){

    document.getElementById("red").checked=false

</script>

</head>

<body>

<form>

你更喜歡哪種顔色?<br>

<input type="radio" name="colors" id="red">紅色<br>

<input type="radio" name="colors" id="blue">藍色<br>

<input type="radio" name="colors" id="green">綠色

</form>

<button type="button" onclick="check()">選擇 "紅色"</button>

<button type="button" onclick="uncheck()">不選擇 "紅色"</button>

</body>

</html>

Radio checked 屬性