繁体   English   中英

无需重写多行即可使警报更漂亮

[英]Making alerts prettier without rewriting many lines

我知道漂亮的警报框有很多很好的插件,但是我已经发出了很多警报,所以我想问一下是否可以在不重写代码中的所有alert function 调用并用其他替换这个 function 的情况下使这些警报更漂亮?

你可以劫持默认的window.alert function:

window.__oldAlert__ = window.alert;
window.alert = function () {
    // your custom alert code here
};

演示: http://jsfiddle.net/mattball/jMEha/


编辑

我需要写什么才能将其更改为此插件? http://thrivingkings.com/apprise

您的页面将需要 jQuery 以及 Apprise JS 和 CSS 文件。

window.__oldAlert__ = window.alert;
window.alert = function () {
    apprise.apply(this, arguments);
};

演示: http://jsfiddle.net/mattball/exgBs/

没有人可以阻止您覆盖本机window.alert方法。 如果您负责代码库,则可能如下所示:

(function _mynameSpace() {
    window.alert = function() { 
        $('#mydialogDiv').dialog({
            modal: true,
            // etc.
        });
    };
}());

您可以将window.alert替换为 function 以某种自定义方式执行通知。 这是一个简单的例子:

<script>
  window.alert = console.log;
</script>

随后对alert的调用将真正调用console.log

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM