Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...