【发布时间】:2016-08-20 22:40:19
【问题描述】:
我有一些 html 选择:
<select class="form-control, dropdown" id="delperffrom" name="delperffrom">
. . .
<select class="form-control, dropdown" id="delperfto" name="delperfto">
. . .
我想将它们初始化为“无价值”,所以有这个 javascript,它可以工作:
document.getElementById("delperffrom").selectedIndex = -1;
..还有这个 jQuery,它没有:
$("#delperfto").selectedIndex = -1;
为什么 jQuery 不起作用?
【问题讨论】:
-
不相关但 css 类仅由空格分隔。
-
api.jquery.com/?s=selectedIndex 显示此属性不存在,但显示可用于更改
selectedIndex的方法。 -
可能是
$("#delperfto")[0].selectedIndex = -1;? -
另外,类列表中不要放逗号:“form-control dropdown”是正确的。
标签: javascript jquery html-select