如何为 HTML <select> 设置默认值?元素? [英] How can I set the default value for an HTML <select> element?
本文介绍了如何为 HTML <select> 设置默认值?元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为在 元素上添加一个
"value"
属性集会导致 包含我提供的
"value"
默认选择:
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 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?
推荐答案
将 selected="selected"
设置为您希望成为默认选项的选项.
Set selected="selected"
for the option you want to be the default.
<option selected="selected">
3
</option>
这篇关于如何为 HTML <select> 设置默认值?元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文