搜索数组inArray但忽略大小写 [英] Search array inArray but ignore case

查看:88
本文介绍了搜索数组inArray但忽略大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望我提供了清晰的标题.

Hope I provided a clear title.

我正在创建一个包含所有选项,修剪空白和存储的数组. (如果我在处理过程中出错,请更正我).输入更改时,如果选项数组返回false,则清除下一个字段,否则,存储唯一的新值并将其放在下一个字段中.

I am creating an array comprised of all options, trimming whitespace, and storing. (correct me if im wrong in my process). On input change, if option array returns false, clear the next field, else, store the unique new value and place in next field.

如果数组包含:

blue
black
brown

,然后搜索BLUE或Blue或BLue ...等,结果返回false.我想我要求区分大小写的逻辑,但不确定如何合并.

and I search for BLUE or Blue or BLue...etc, the result returns false. I guess im asking for caseInsensitive logic, but not sure how I can incorporate.

我已经通过反复试验完成了所有步骤,因此如果您愿意的话,请随时进行完善.另外,这必须在jquery 1.3的规范内

Ive done this all on trial and error so please feel free to refine if your time allots. Also, this needs to be within spec of jquery 1.3

http://jsfiddle.net/arkjoseph/dRpmq/2/

谢谢您的帮助.

推荐答案

由于看起来您可以控制这些值(并使它们变为小写),因此可以从以下位置进行一个非常简单的更改:

Since it looks like you have control of the values (and are making them lowercase), you can do a pretty simple change from:

if (($.inArray((this.value), option) > 0)

if (($.inArray((this.value.toLowerCase()), option) > 0)

演示位于 http://jsfiddle.net/dRpmq/3/

这篇关于搜索数组inArray但忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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