Javascript SweetAlert 不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44821226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:44:52  来源:igfitidea点击:

Javascript SweetAlert not working?

javascriptsweetalert

提问by brazorf

This html document

这个html文件

<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
</head>

<script>
    SweetAlert('a', 'b', 'c');
</script>

is not working. I get Uncaught ReferenceError: SweetAlert is not defined

不管用。我得到Uncaught ReferenceError: SweetAlert is not defined

If i use swal()instead of SweetAlert()i get

如果我使用swal()而不是SweetAlert()我得到

Uncaught TypeError: Cannot read property 'className' of null

Uncaught TypeError: Cannot read property 'className' of null

The same test with sweetalert2

与sweetalert2相同的测试

<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.5/sweetalert2.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.5/sweetalert2.common.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.5/sweetalert2.min.js"></script>
</head>

i get the following

我得到以下

Uncaught ReferenceError: module is not defined
    at sweetalert2.common.min.js:1

sweetalert2.min.js:1 Uncaught TypeError: Cannot read property 'querySelector' of null
    at u (sweetalert2.min.js:1)
    at c (sweetalert2.min.js:1)
    at U (sweetalert2.min.js:1)
    at e (sweetalert2.min.js:1)
    at test:8

回答by Weedoze

Error A

错误 A

You were calling SweetAlert(...)instead of sweetAlert(...). First letter should be in lower case.

您正在调用SweetAlert(...)而不是sweetAlert(...). 第一个字母应该小写。

Error B

错误 B

If you are using the third argument, it should be warning, error, successor info

如果您使用第三个参数,它应该是warning, error,successinfo

sweetAlert("a", "b", "error");
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

回答by Ali

You don't need a name like sweetAlert. You can use swal('Title', 'Message', 'type')instead of sweetAlert

你不需要像sweetAlert这样的名字。您可以使用swal('Title', 'Message', 'type')代替 sweetAlert

swal("HEY", "Message", "warning")
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

回答by JAGAT DAS

//Define.

//定义。

    <script src="js/sweetalert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/sweetalert.css">

//For Call

//调用

    function callSweetMsg(){
        swal({
        title: "Error!",``
        text: "Here's my error message!",
        type: "error",
        confirmButtonText: "Cool"
       });
    }

回答by Pankaj

Type must be in small case like warning, error, success or info.

类型必须是小写,如警告、错误、成功或信息。