【发布时间】:2011-06-08 11:33:10
【问题描述】:
我想将之前选择的选项设置为在页面加载时显示。我用下面的代码试了一下:
$("#gate").val('Gateway 2');
与
<select id="gate">
<option value='null'>- choose -</option>
<option value='gateway_1'>Gateway 1</option>
<option value='gateway_2'>Gateway 2</option>
</select>
但这不起作用。有什么想法吗?
【问题讨论】:
-
实际上它应该是这样工作的,你确定你在 document.ready() 中设置了值吗? Maybe the code is executed when the selectbox isn't ready yet.
标签: jquery html jquery-selectors html-select