jQuery 1.10.1在选择时设置不存在的值 [英] jQuery 1.10.1 setting non existing value on select

查看:114
本文介绍了jQuery 1.10.1在选择时设置不存在的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释这种行为吗?

Can someone explain this behavior:

<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.

jsFiddle

推荐答案

使用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.

这是v1.10中修复的错误#13514 的修复程序.设置无效值应该清除选择(在v1.10 +中会执行此操作),而不是将其保留为默认(第一个)选项(v1.9).

It's the fix to bug #13514, fixed in v1.10. Setting an invalid value should clear the select (which it does in v1.10+), not leave it at the default (first) option (v1.9).

这篇关于jQuery 1.10.1在选择时设置不存在的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆