问题描述
|
我知道有很多不错的警报框插件,但是我已经发出了很多警报,所以我想问一下是否有可能使这些警报更漂亮而不用重写代码中的所有“ 0”函数调用并替换此函数。和其他人?
解决方法
您可以劫持默认的
window.alert
函数:
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
替换为以某种自定义方式执行通知的函数。这是一个简单的示例:
<script>
window.alert = console.log;
</script>
随后调用alert
会真正调用call9ѭ。