javascript - layer的confirm框,为什么不执行对应的函数呢?
本文介绍了javascript - 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;
}
);
}
解决方案
加一句e.preventDefault()
,然后在function check_form()
里面加一个e
也就变成
<form method="post" action="<%=basePath%>questionnaire/save" onsubmit="return check_form()" id="form_1">
</form>
function check_form(e){
e.preventDefault();
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;
}
);
}
这篇关于javascript - layer的confirm框,为什么不执行对应的函数呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文