html选择列表 - 当大小为10

时间:2015-12-17 03:24:31

标签: javascript jquery html html-select

我有一个html选择列表,我用它来显示很多选项。

我的选择大小为10而我正在使用autofocus

如何重新显示选择列表,以便在页面加载时显示所选选项,即使所选选项不在前10个选项中,如下所示:

enter image description here

目前,当页面加载时,选择列表显示如下(选择选项19,但不显示):

enter image description here

这是我的选择列表代码:

<select id="id_preview_style_select" name="preview_style" title="Preview Style" size="10" autofocus>
    ....
    ....
</select>

1 个答案:

答案 0 :(得分:1)

您应该将选定的焦点属性添加到所需的选项标记

<select id="id_preview_style_select" name="preview_style" title="Preview Style" size="10" autofocus>
    ....

    <option value="10" selected focus> 20 </option>

    ....
</select>

查看此jsFiddle