这里是我的测试:为什么这个函数返回真正的而不是虚假
var test = function() {
$.each([1, 2], function() {
if(true !== false) { // it is just an example
alert('I am here');
return false; // how should I make the function test to stop or to exit here?
}
});
return true;
};
alert(test());
我想test
函数返回false,但它返回true。
为什么?我应该如何修复代码?请参阅评论了解更多详情。
如果你必须迭代一组jQuery对象,你可以很容易。你可以使用.filter(...)找到匹配给定谓词的第一个元素。first() –