layer的confirm框,为什么不执行对应的函数呢?

1.会弹出123
2.但是不会弹出1
3.也不会弹出2
4.确认提交confirm框会一闪而过,之后表单提交


<form method="post" action="<%=basePath%>questionnaire/save"  onsubmit="return check_form()" id="form_1">

</form>

function check_form(){

    alert(123);

    layer.confirm('确认提交?', 

            

            {

              btn: ['确定','取消'] //按钮

    

            }, 

            

            function(index){

                alert(1);

              layer.msg('感谢您参与平台调研,稍后会有工作人员联系您!', {icon: 1});

              return true;

            },

            function(index){

                alert(2);

                layer.msg('已取消!', {icon: 1});

                return false;

            }

        );

}


慕容森
浏览 400回答 1
1回答

繁华开满天机

加一句e.preventDefault(),然后在function check_form()里面加一个e也就变成<form method="post" action="<%=basePath%>questionnaire/save"&nbsp; onsubmit="return check_form()" id="form_1"></form>function check_form(e){&nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; alert(123);&nbsp; &nbsp; layer.confirm('确认提交?',&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btn: ['确定','取消'] //按钮&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(index){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(1);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer.msg('感谢您参与平台调研,稍后会有工作人员联系您!', {icon: 1});&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(index){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer.msg('已取消!', {icon: 1});&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; );}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript