How to select a radio button by default?(默认情况下如何选择单选按钮?)
问题描述
我有一些单选按钮,我希望在加载页面时将其中一个设置为默认选中.我该怎么做?
I have some radio buttons and I want one of them to be set as selected by default when the page is loaded. How can I do that?
<input type="radio" name="imgsel" value="" />
推荐答案
XHTML 解决方案:
XHTML solution:
<input type="radio" name="imgsel" value="" checked="checked" />
请注意,checked 属性的实际值并不重要;这只是分配 "checked" 的约定.最重要的是,像 "true" 或 "false" 这样的字符串没有任何特殊含义.
Please note, that the actual value of checked attribute does not actually matter; it's just a convention to assign "checked". Most importantly, strings like "true" or "false" don't have any special meaning.
如果您的目标不是 XHTML 一致性,您可以将代码简化为:
If you don't aim for XHTML conformance, you can simplify the code to:
<input type="radio" name="imgsel" value="" checked>
这篇关于默认情况下如何选择单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:默认情况下如何选择单选按钮?
基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
