默认情况下如何选择单选按钮?
我有一些单选按钮,我希望在加载页面时将其中一个设置为默认选中.我该怎么做?
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>
相关文章