原文:https://blog.csdn.net/qingzhongren/article/details/52503137
在做需求的时候,用到了jquery.each循环,
对循环遍历的值进行判断,不符合条件的,return false,给出提示。
但是遇到的情况是,return false 后,还能继续执行,都走了后台,感觉没有校验住,但又觉得代码写的没错呀,然后搜索,搜到了这个文章,解疑问了。
加了一个flag标识判断就好了
var isFlag = true;//标识
// 判读有米有选中题目
if ($('.question-item-bxbox').length > 3) {
$('.question-item-bxbox').each(function(){
var _$this=$(this);
if (_$this.find('.active').length < 1) {
layer.msg("题目都是必选哦~");
isFlag = false; //设置标识
return false;
}
else{
isFlag = true;
}
});
}
if (isFlag == true ) {
$t.attr('data_lock',1).addClass('disable');
$.ajax({
url : $t.attr('data-url'),
type : 'post',
data : paramGlobal,
dataType : 'json',
success : function(r){
layer.msg(r.message);
},
error : function(){
layer.msg("Oops,网络发生错误了,请刷新重试~");
},
complete:function(){
$t.removeAttr('data_lock').removeClass('disable');
}
});
}
留言与评论(共有 0 条评论) “” |