Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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默认警报_Javascript_Php_Sweetalert - Fatal编程技术网

通过在过程中使用甜警报更改JavaScript默认警报

通过在过程中使用甜警报更改JavaScript默认警报,javascript,php,sweetalert,Javascript,Php,Sweetalert,我想问,如何在process.php中调用sweet alert html格式的示例: <!DOCTYPE html> <html> <head> <title>Sweet Alert</title> <link rel="stylesheet" type="text/css" href="plugins/sweetalert/sweetalert.css"> <script type="text/javascript

我想问,如何在process.php中调用sweet alert

html格式的示例:

<!DOCTYPE html>
<html>
<head>
<title>Sweet Alert</title>
<link rel="stylesheet" type="text/css" href="plugins/sweetalert/sweetalert.css">
<script type="text/javascript" src="plugins/sweetalert/sweetalert.min.js"></script>
</head>
<body>
<button onclick="sweet()">Sweet Alert</button>
<script>
function sweet (){
swal("Good job!");
}
</script>
</body>
</html>

甜蜜的警觉
甜蜜的警觉
函数sweet(){
斯瓦尔(“干得好!”);
}

那么,如果将其放在process.php中,会怎么样呢

示例有两个字段:

tes.php:

<form method="post" action="proses.php">
<label>NIK</label><br>
<input type="text" name="nik"><br>
<label>Confirm NIK</label><br>
<input type="text" name="confirmnik"><br><br>
<button type="submit" name="submit">Cek</button>
</form>

尼克

确认NIK


塞克
process.php:

<?php
    $nik        = $_POST['nik'];
    $confirmnik = $_POST['confirmnik'];

    if ($nik<>$confirmnik)
    {
        echo "<script language='javascript'>alert('nik and confirm nik do not match !');window.history.back();</script>";
    }
    else
    {
        echo "<script language='javascript'>alert('ok');window.history.back();</script>";
    }
?>

您应该能够无缝地将
警报
替换为
swal

您唯一的问题是调用
window.history.back
函数。您需要将其放入回调中,因为sweet alert不会像
alert
那样阻止线程

您可以使用:

因此,您的JS代码看起来像:

swal('nik and confirm nik do not match !').then(() => {window.history.back()});
完整的PHP代码如下所示:

<?php
    $nik        = $_POST['nik'];
    $confirmnik = $_POST['confirmnik'];

    if ($nik<>$confirmnik)
    {
        echo "<script language='javascript'>swal('nik and confirm nik do not match !').then(() => { window.history.back(); });</script>";
    }
    else
    {
        echo "<script language='javascript'>swal('ok').then(() => { window.history.back(); });</script>";
    }
?>

您是否尝试过将
警报('nik and…
更改为
swal('nik and…
?您很有帮助,但仍然无法工作。我应该将库甜警报放在哪里?在test.php或process.php中?将其放在
test.php
中,在
中我已经尝试过了。但是,当跳转到文件process.php时,什么都没有发生,只是显示一个空白视图。您在生成的HTML中尝试过吗还有?还有,你在控制台里有错误吗?耶..看我的代码和图片:和