Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

html - 如何默认选择一个单选按钮? [重复](How to select a radio button by default? [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

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=""  /> 
  ask by jslearner translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

XHTML solution:

(XHTML解决方案:)

<input type="radio" name="imgsel" value="" checked="checked" />

Please note, that the actual value of checked attribute does not actually matter;

(请注意, checked属性的实际值实际上并不重要;)

it's just a convention to assign "checked" .

(它只是一个分配"checked"的约定。)

Most importantly, strings like "true" or "false" don't have any special meaning.

(最重要的是,像"true""false"这样的字符串没有任何特殊含义。)

If you don't aim for XHTML conformance, you can simplify the code to:

(如果您不瞄准XHTML一致性,则可以将代码简化为:)

<input type="radio" name="imgsel" value="" checked>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...