使用Jquery 1.8.0 return false不会中断each()循环

使用Jquery 1.8.0 return false不会中断each()循环,jquery,loops,break,each,Jquery,Loops,Break,Each,这是我正在使用的脚本 $('.row').each(function(){ $(this).each(function(){ if($(this).find('.name').val()==""){ $(this).find('.name').val(data.name); $(this).find('.autonomy').val(data.autonomy);

这是我正在使用的脚本

    $('.row').each(function(){
        $(this).each(function(){
            if($(this).find('.name').val()==""){

                $(this).find('.name').val(data.name);
                $(this).find('.autonomy').val(data.autonomy);
                $(this).find('.purpose').val(data.purpose);
                $(this).find('.flow').val(data.flow);
                $(this).find('.relatedness').val(data.relatedness);
                $(this).find('.challenge').val(data.challenge);
                $(this).find('.mastery').val(data.mastery);
                $(this).find('.colour').val(data.colour);
                done=true;
            }
            if(done==true){
                alert("here");
                return false;
            }
        });
    });

它似乎完全忽略了返回错误,我似乎不知道为什么

无需嵌套
每个
。移除内部的一个,并且
返回false
将起作用:

$(".row").each(function() {
    // ...
    if (done === true) {
        alert("here");
        return false;
    }
});​

先给我们看看你的DOM

返回的值只会停止第二个each()。如果你想阻止第一个,你需要用另一种方式


很抱歉,我不能发表评论,但我的声誉不允许发表评论。

为什么有两个
。每个()
?这确实是问题所在!当天晚些时候解决了:)你不知道他的HTML,一定要确保他不需要嵌套的each。@FábioSilva相信我,这没关系。但也许他想做一个嵌套循环(针对每行中的每个元素)。您的解决方案只运行每一行。但我明白您在本例中的观点:第二个this==到第一个this,所以他总是访问行元素