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
396 views
in Technique[技术] by (71.8m points)

html - 如何设置HTML的默认值 <select>元件?(How can I set the default value for an HTML <select> element?)

I thought that adding a "value" attribute set on the <select> element below would cause the <option> containing my provided "value" to be selected by default:

(我认为在下面的<select>元素上添加"value"属性集会导致默认情况下选中包含我提供的"value"<option> :)

 <select name="hall" id="hall" value="3"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> 

However, this did not work as I had expected.

(但是,这没有按我预期的那样工作。)

How can I set which <option> element is selected by default?

(如何设置默认选择哪个<option>元素?)

  ask by Jichao translate from so

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

1 Reply

0 votes
by (71.8m points)

Set selected="selected" for the option you want to be the default.

(为要设置为默认的选项设置selected="selected" 。)

<option selected="selected">
3
</option>

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

...