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
295 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 Answer

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>

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

2.1m questions

2.1m answers

60 comments

56.9k users

...