Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript sweetAlert弹出窗口在一秒钟后自动关闭_Javascript_Sweetalert - Fatal编程技术网

JavaScript sweetAlert弹出窗口在一秒钟后自动关闭

JavaScript sweetAlert弹出窗口在一秒钟后自动关闭,javascript,sweetalert,Javascript,Sweetalert,我有一个SweetAlert弹出窗口,但它会自动关闭。通常,它应该一直保持到用户单击“确定”。(我已包括并测试了所有SweetAlert文件。) 提交 函数myFunction(){ swal(“已提交!”,“您的问题已提交!”,“成功”); } 看起来像是表单提交,因此当您单击按钮时,页面将刷新。这就是为什么您会看到一秒钟的警报,但它会隐藏 <button class="btn btn-success" type="submit" name="submit" onclick="my

我有一个SweetAlert弹出窗口,但它会自动关闭。通常,它应该一直保持到用户单击“确定”。(我已包括并测试了所有SweetAlert文件。)

提交


函数myFunction(){
swal(“已提交!”,“您的问题已提交!”,“成功”);
}

看起来像是表单提交,因此当您单击按钮时,页面将刷新。这就是为什么您会看到一秒钟的警报,但它会隐藏

<button class="btn btn-success" type="submit" name="submit" onclick="myFunction()">Submit</button>

请注意,如果您的按钮是表单提交的一部分,则表示当前不支持该按钮。您可以将按钮更改为常规按钮(而不是提交按钮),并在sweetalert回调中以编程方式从回调提交表单。

我也有类似问题。。 当在弹出窗口外单击时,弹出窗口将自动关闭并快速更改页面

我为stop close sweetalert本身尝试了这段代码,并在用户单击sweetalert窗口的“OK”时刷新页面

HTML:


javascript

<script type="text/javascript">
function myFunction() {
  var full=document.myform.full.value;
  var last=document.myform.last.value;
  if (full==null || last==null){
    swal("Error...!!!!!!");
    return false;
}else{
    swal("Congrats!", ", Your account is created!", "success");
    return true;}
}
</script>

函数myFunction(){
var full=document.myform.full.value;
var last=document.myform.last.value;
if(full==null | | last==null){
swal(“错误…!!!!!”);
返回false;
}否则{
swal(“恭喜!”,“您的帐户已创建!”,“成功”);
返回true;}
}

您尝试过什么?如果这是一个提交按钮,你的页面是否会在警报完成之前更改?只是想附加一句:即使你更改了按钮的类型,你也需要从标签中删除按钮,如果它是在标签中的话。这节省了我的时间
<button class="btn btn-success" type="submit" name="submit" onclick="myFunction()">Submit</button>
   <button class="btn btn-success" type="button" onclick="myFunction()">Submit</button>
<form  method="post" action="contact.php" name="myform" onsubmit="return myFunction()">

<input type="text" class="form-control" name="full" placeholder="* Full Name" required="" >

<input type="text" class="form-control" name="last" placeholder="* Last Name" required="">

<input type="submit" value="send" name="sends" class="btn btn-lg">

</form>
<script type="text/javascript">
function myFunction() {
  var full=document.myform.full.value;
  var last=document.myform.last.value;
  if (full==null || last==null){
    swal("Error...!!!!!!");
    return false;
}else{
    swal("Congrats!", ", Your account is created!", "success");
    return true;}
}
</script>