如何break/exit jquery.each()方法

洼地云 ai-quyi.png

在使用jQuery的each()方法时,如何跳出循环呢?根据官方文档的说明,可以使用return false进行break,如下:

jquery.jpg

We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.

示例:

function checkIsSearchForNothing() {
    var result = false;
    $("#searchForm").find("input[type='text']").each(function () {
        if ($(this).val() != null && $(this).val() != '') {
            result = true;
            return false;
        }
    });
    return result;
}

参考:

  1. How to break/exit from a each() function in JQuery? [duplicate]
  2. jQuery.each()
赞(0)
未经允许禁止转载:优米格 » 如何break/exit jquery.each()方法

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系

登录

找回密码

注册