一秒钟后,JavaScript sweetAlert弹出窗口将自行关闭 [英] JavaScript sweetAlert popup closes itself after a quick second
本文介绍了一秒钟后,JavaScript sweetAlert弹出窗口将自行关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个SweetAlert弹出窗口,但它会自动关闭.通常,它应该一直保留到用户单击确定"为止.(我已经包含并测试了所有SweetAlert文件.)
I have a SweetAlert popup, but it is closing itself automatically. Normally it should stay until user clicks 'OK'. (I have included and tested all SweetAlert files.)
<button class="btn btn-success" type="submit" name="submit" onclick="myFunction()">Submit</button>
<script>
function myFunction() {
swal("Submitted!", "Your Issue has been submitted!", "success");
}
</script>
推荐答案
看起来像是表单提交,因此,当您单击按钮时,页面会刷新.这就是为什么您看到警报一秒钟并隐藏它的原因.
Looks like it's a form submit, So when you click the button the page refreshes.That's why you see the alert for a second and it hides.
<button class="btn btn-success" type="submit" name="submit" onclick="myFunction()">Submit</button>
您必须将按钮类型更改为 button
.
You must change the button type to be button
.
<button class="btn btn-success" type="button" onclick="myFunction()">Submit</button>
这篇关于一秒钟后,JavaScript sweetAlert弹出窗口将自行关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文