【问题标题】:Sweetalert dialog won't showSweetalert 对话框不会显示
【发布时间】:2016-05-26 17:10:32
【问题描述】:
window.alert = function (text) {
    swal({
        title: "Computer says:",
        text: text,
        timer: 3000,
        animation: "slide-from-top"
    });
    return true;
};

function run(input) {
    if (input[0] == "alert") {
        ta = input.slice(1, input.length);
        tap = ta.join(" ");
        alert(tap);
    }
}

当我拨打run(["alert", "hello"]); in the javascript console 时,它工作正常。 但是当我type in alert hello, in my console 时,对话框会短暂闪烁并消失。这里发生了什么,我该如何阻止它?谢谢!

【问题讨论】:

    标签: javascript html css dialog sweetalert


    【解决方案1】:

    它工作正常,即使在控制台中我也看不出有什么问题:

      <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <link rel="stylesheet" type="text/css" href="sweetalert.css">
    </head>
    <body>
    <script src="sweetalert.min.js"></script>
    <script type="text/javascript">
        window.alert = function (text) {
        swal({
            title: "Computer says:",
            text: text,
            timer: 3000,
            animation: "slide-from-top"
        });
        return true;
        };
        function run(input) {
        if (input[0] == "alert") {
            ta = input.slice(1, input.length);
            tap = ta.join(" ");
            alert(tap);
        }
    }
    run(["alert", "hello"]);
    </script>
    </body>
    </html>
    

    【讨论】:

    • 当我不更改 window.alert() 函数时,它可以正常工作,但样式当然不会显示。
    • 也许你没有导入 sweetalert css
    • 这是我的导入代码:&lt;script src="dist/sweetalert.min.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" type="text/css" href="dist/sweetalert.css"&gt;
    • js前要导入css
    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多