本文介绍了检查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
});
谢谢
推荐答案
查看该文档页面,似乎您不能向该函数传递多个值.
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中是否有多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!