2012-12-05 55 views
-1

这是我正在使用的脚本。使用jquery 1.8.0返回false不会破坏each()循环

$('.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,我似乎无法解决为什么!

+2

为什么有两个'.each()'? – Jack

+0

确实是这个问题!在当天晚些时候完成它:) – daverage

回答

2

无需嵌套each。删除内部和return false将工作:

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

你不知道他的HTML确实不需要每个嵌套。 –

+0

@FábioSilva相信我,没关系。 – VisioN

+0

但也许他想做一个嵌套循环(每行内的每个元素)。你的解决方案只运行每一行。但我在这种情况下看到你的观点:第二**这**是第一**这个**,所以他总是访问*行*元素 –

2

向我们显示您的DOM首先。

返回,你只停止第二个each()。如果你想停止第一个,你需要以其他方式来完成。

对不起,我不能评论,但我的声誉不允许。

+1

现在它! :) –