Input Radio value 屬性
定義和用法
value
屬性設置或返回單選按鈕的 value 屬性的值。
對於單選按鈕,value 屬性的內容不會出現在用戶界面中。value 屬性僅在提交表單時才有意義。如果在提交表單時單選按鈕處於選中狀態,則單選按鈕的名称與 value 屬性的值一起發送(如果單選按鈕未選中,則不發送任何信息)。
提示:請為同一組中的單選按鈕定義不同的值,以便(在伺服器端)識別哪個選項被選中。
另請參考:
HTML 參考手冊:HTML <input> value Atributo
實例
例子 1
獲取單選按鈕的 value 屬性的值:
var x = document.getElementById("myRadio").value;
例子 2
更改單選按鈕的 value 屬性的值:
document.getElementById("myRadio").value = "newRadioBtnValue";
例子 3
使用單選按鈕和文本輸入字段來顯示所選單選按鈕的值:
document.getElementById("result").value = browser;
Syntax
Return value attribute:
radioObject.value
Set value attribute:
radioObject.value = text
Attribute Value
Value | Description |
---|---|
text | Specifies the value associated with the input (this is also the value sent when submitting). |
Technical Details
Return value: | String value, representing the value of the radio button's value attribute. |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |