RadioNodeList.value - Web APIs 编辑
If the underlying element collection contains radio buttons, the RadioNodeList.value
property represents the checked radio button. On retrieving the value
property, the value
of the currently checked
radio button is returned as a string. If the collection does not contain any radio buttons or none of the radio buttons in the collection is in checked
state, the empty string is returned. On setting the value
property, the first radio button input element whose value
property is equal to the new value will be set to checked
.
Syntax
value = radioNodeList.value; radioNodeList.value = string;
Example
HTML
<form>
<label><input type="radio" name="color" value="blue">Blue</label>
<label><input type="radio" name="color" value="red">Red</label>
</form>
JavaScript
// 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';
Result
Specifications
Specification | Status | Comments |
---|---|---|
HTML Living Standard The definition of 'RadioNodeList.value' in that specification. | Living Standard | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
- The
<form>
,<fieldset>
,<input>
elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论