jQuery 1.10.1在select上设置非现有值

gyo*_*fov 5 javascript jquery select

有人可以解释这种行为:

<select id ="test">
       <option value="-1">---All---</option>
       <option value="1">first</option>
       <option value="2">second</option>
</select>

$('#test').val(200);
Run Code Online (Sandbox Code Playgroud)

使用jQuery 1.10.1,select的值为null,但使用jQuery 1.9.1时,该值是第一个选项.

的jsfiddle

T.J*_*der 6

使用jQuery 1.10.1,select的值为null,但使用jQuery 1.9.1时,该值是第一个选项.

这是修复了错误#13514,修复于v1.10.设置无效值应清除select(在v1.10 +中执行),而不是将其保留为默认(第一个)选项(v1.9).