代码之家  ›  专栏  ›  技术社区  ›  dkinzer

如何在jquery中突破每个$.

  •  2
  • dkinzer  · 技术社区  · 15 年前

    当条件满足时,如何从下面的jquery中分离出每个方法;

    var rainbow = {'first' : 'red', 'second' : 'orange', 'third' : 'yellow'};
    
    $.each(rainbow, function (key, color) {
    
      if (color == 'red') {
    
        //do something and then break out of the each method
        alert("i'm read, now break.");
    
      }
    
    });
    
    6 回复  |  直到 15 年前
        2
  •  3
  •   Diego    15 年前
    var rainbow = {'first' : 'red', 'second' : 'orange', 'third' : 'yellow'};
    
    $.each(rainbow, function (key, color) {
    
      if (color == 'red') {
    
        //do something and then break out of the each method
        alert("i'm read, now break.");
    
        return false;
    
      }
    
    });
    
        3
  •  2
  •   tsimbalar    15 年前

    如jquery页面上为 $.each :

    我们可以在 通过使 回调函数返回false。 返回非false与 for循环中的continue语句;它 将立即跳到下一个 迭代。

    请谷歌你搜索的条款,然后张贴在这里!很遗憾,jquery有史以来最好的文档之一,如果你不费心去阅读它的话!

        4
  •  1
  •   Spudley Pat    15 年前

    这个 JQuery documentation for each 国家:

    通过使回调函数返回false,我们可以在特定的迭代中中断$.each()循环。返回非false与for循环中的continue语句相同;它将立即跳到下一个迭代。

    它还提供了示例。

        5
  •  1
  •   zod    15 年前
    <script>
        var arr = [ "one", "two", "three", "four", "five" ];
    
        jQuery.each(arr, function() {
          $("#" + this).text("Mine is " + this + ".");
           return (this != "three"); // will stop running after "three"
       });
    
    
    </script>
    

    试试这个

    http://api.jquery.com/jQuery.each/

        6
  •  1
  •   Mukesh Yadav    15 年前

    我们不能在jquery函数中使用break和continue
    试试这个

    var rainbow = {'first' : 'red', 'second' : 'orange', 'third' : 'yellow'};
    
    $.each(rainbow, function (key, color) {
    
      if (color == 'red') {
        //do something and then break out of the each method
        alert("i'm read, now break.");
        return false;
      }
      alert(color);
    });