有没有办法定义要在单选按钮的 HTML 表单中选择的默认值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8967795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:42:08 来源:igfitidea点击:
Is there a way to define a default value to be selected in an HTML Form of Radio Buttons?
提问by wide_eyed_pupil
<body>
<form>
<input type="radio" name="amount" value="10"/>  
<input type="radio" name="amount" value="25"/>  
<input type="radio" name="amount" value="50"/>  
<input type="radio" name="amount" value="100"/> 0 
<input type="radio" name="amount" value="250"/> 0 
<input type="radio" name="amount" value="other"/> Other
</form>
</body>
To make the $50 option the default selection what HTML code would I use?
要使 $50 选项成为默认选择,我将使用什么 HTML 代码?
回答by stealthyninja
Just set it as checked:
只需将其设置为选中:
<body>
<form>
<input type="radio" name="amount" value="10"/>  
<input type="radio" name="amount" value="25"/>  
<input type="radio" name="amount" value="50" checked="checked" />  
<input type="radio" name="amount" value="100"/> 0 
<input type="radio" name="amount" value="250"/> 0 
<input type="radio" name="amount" value="other"/> Other
</form>
</body>
回答by Bhavin Vora
Just Simply Add
只需简单添加
checked="checked"
检查=“检查”
in a declaration of Button Which u want to be default Checked.
在 Button 的声明中,您希望默认选中该按钮。
回答by craigmj
<input type="radio" name="amount" value="50" checked="checked"/>