jQuery each 迴圈中的 break 和 continue

  1. continue :return true;   
  2. break :return false;  

jQuery loops are implemented by calling the each function on a jQuery object. The argument of the each function is another function. This function argument is executed for each element in the jQuery array. This is different from a normal javascript loop and therefore the break and continue statements do not work in a jQuery loop.

Fortunately there is another way for breaking and continuing a jQuery loop. You can break a jQuery loop by returning false in the function argument. A continue can be implemented by just doing a return without specifying a return value or by returning any other value than false.

留言