谁能解释一下这种行为:
<select id ="test">
<option value="-1">---All---</option>
<option value="1">first</option>
<option value="2">second</option>
</select>
$('#test').val(200);
使用jQuery 1.10.1 select的值为null, 但使用 jQuery 1.9.1 该值是第一个选项。
最佳答案
Using the jQuery 1.10.1 the value of the select is null, but using jQuery 1.9.1 the value is the first option.
这是对 bug #13514 的修复,已在 v1.10 中修复。设置无效值应清除选择(它在 v1.10+ 中执行),而不是将其保留在默认(第一个)选项 (v1.9)。
关于javascript - jQuery 1.10.1 在选择时设置不存在的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22983511/