检查inArray中是否有多个项目 [英] check if multiple items inArray

查看:34
本文介绍了检查inArray中是否有多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jquery的inArray函数检查数组中是否包含多个项目?

Is it possible to check if multiple items are contained within an array using jquery's inArray function?

if ($.inArray('foo' && 'bar', array) == -1) {
    // Neither foo or bar in array
});

谢谢

推荐答案

使用 ,您可以(引用):

在 数组并返回其索引(如果为-1,则返回-1 找不到).

Search for a specified value within an array and return its index (or -1 if not found).

查看该文档页面,似乎您不能向该函数传递多个值.

Looking at that documentation page, it doesn't seem you can pass more than one value to that function.


因此,为什么不两次调用该函数:'foo'一次,'bar'一次:


So, why not call that function twice : one time for 'foo', and one time for 'bar' :

if ($.inArray('foo', array) == -1 && $.inArray('bar', array) == -1) {
    // Neither foo or bar in array
}

这篇关于检查inArray中是否有多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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