RadioNodeList: value 屬性

如果底層元素集合包含單選按鈕,則 RadioNodeList.value 屬性表示被選中的單選按鈕。在檢索 value 屬性時,當前 checked 狀態的單選按鈕的 value 將作為字串返回。如果集合不包含任何單選按鈕,或者集合中的任何單選按鈕都處於 checked 狀態,則返回空字串。在設定 value 屬性時,value 屬性等於新值的第一個單選按鈕輸入元素將被設定為 checked 狀態。

示例

HTML

html
<form>
  <label><input type="radio" name="color" value="blue" />Blue</label>
  <label><input type="radio" name="color" value="red" />Red</label>
</form>

JavaScript

js
// Get the form
const form = document.forms[0];

// Get the form's radio buttons
const radios = form.elements["color"];

// Choose the "red" option
radios.value = "red";

結果

規範

規範
HTML
# dom-radionodelist-value

瀏覽器相容性

另見

  • <form><fieldset><input> 元素。