是否jQuery.inArray
处理变量?如果是,为什么这个例子不起作用?
jQuery代码:
var arrayOfitems = ["1","2","33","34","35","36","37","38","39","40","41","42","77"];
$(document).ready(function(){
var searchN = $(#some-element-id).val(); // var searchN = 2;
if($.inArray(searchN, arrayOfitems) !== -1 )
{
alert('is in array');
}
else
{
alert('is not in array');
}
});
小提琴: