$('.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 来实现。

相关文章:

  • 2021-08-31
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-11-23
猜你喜欢
  • 2021-11-24
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
相关资源
相似解决方案