关于layer.alert()函数不调用

代码:

var ms = $("input[name='mstj']:checked").val();

if(ms === '1'){

  layer.alert('请确认您为免试!');

}

layer.confirm(
  '您确定要保存当前信息吗?',
  {title:['系统消息','background:#e4f4eb;color:#238651;'], btn: ['确定', '取消'],icon: 3},
  function(index){
    $('#form1').ajaxSubmit({

      type:'post',
      dataType:'json',
      url:'student_util.jsp',
      timeout: 20000,
      success:function(data){
        if(data.state=='1'){
          layer.msg('操作成功!',{icon: 6});
          setTimeout('window.location.href="apply_util.jsp"',1000);//setTimeout是js附带的延缓执行函数
        }else{
          layer.msg('操作失败!',{icon: 5});
        }
      },error:function(req, textStatus, errorThrown){
      alert('操作出现异常,请稍后再试!');
    }
  });
});

解决方法

var ms = $("input[name='mstj']:checked").val();
if(ms === '1'){
  layer.alert('请确认您为免试!', function(index){
    layer.confirm(
    '您确定要保存当前信息吗?',
    {title:['系统消息','background:#e4f4eb;color:#238651;'], btn: ['确定', '取消'],icon: 3},
      function(index){
        $("#uploadFile").remove();
        checkSubmitFlg = true;
        $('#form1').ajaxSubmit({
          type:'post',
          dataType:'json',
          url:'student_util.jsp',
          timeout: 20000,
          success:function(data){
            if(data.state=='1'){
            layer.msg('操作成功!',{icon: 6});
            setTimeout('window.location.href="apply_util.jsp"',1000);//setTimeout是js附带的延缓执行函数
          }else{
            layer.msg('操作失败!',{icon: 5});
          }
        },error:function(req, textStatus, errorThrown){
          alert('操作出现异常,请稍后再试!');
      }
    });
   });
  });
}

原因:

  layui的所有组件都是非阻断式的,所以处理的话一般都在msg的end关闭消息后去处理跳转

猜你喜欢

转载自www.cnblogs.com/zying3/p/11097854.html