jQuery中each实现continue和break

$('.required').each(function () {
    // 判断是否有子SPU
    var selected = $('#sub_spu').children('option:selected').val();
    if (selected == 0) {
        if ($(this).hasClass('sub-spu-name')) {
            return true; // continue
        }
    }
    if (!$(this).val()) {
        error_count++;
        if ($(this).hasClass('main-spu-name')) {
            layer.tips('请填写主规格', $(this));
        } else if ($(this).hasClass('main-spu-img')) {
            layer.tips('请上传图片', $(this).parent());
        } else if ($(this).hasClass('sub-spu-name')) {
            layer.tips('请填写副规格', $(this));
        } else if ($(this).hasClass('price')) {
            layer.tips('请填写价格', $(this));
        } else if ($(this).hasClass('origin_price')) {
            layer.tips('请填写原价', $(this));
        } else if ($(this).hasClass('stock')) {
            layer.tips('请填写库存', $(this));
        }  else {
            layer.tips('请填写内容', $(this));
        }
        return false; // break
    }
});

通过return true,return false 来实现。

原文地址:https://www.cnblogs.com/jiqing9006/p/13209502.html