如何选择默认的单选按钮? [英] 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
。最重要的是,像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>
这篇关于如何选择默认的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文