我正在使用$ .grep()函数http://docs.jquery.com/Utilities/jQuery.grep
$.each($.grep( [0,1,2], function(n,i){
return n > 1;
}),
function(){ alert(items matched); // do something }
);
如何警告否。警报框中匹配的项目?另外如何避免检查每个循环的计数?
答案 0 :(得分:3)
将其分为两个步骤:
var arr = $.grep( [0,1,2], function(n,i){
return n > 1;
});
if (arr.length) {
alert("There are some items left after grep!");
$.each(arr, function(){
alert(arr.length); // do something
});
} else {
alert("No items left after grep!");
}