任何JQuery alert()替换JavaScript的本机? [英] Any JQuery alert() replacement for JavaScript's native one?
问题描述
我想用我自己的替换本机javascript alert(),这样我就可以控制主题并让它具有更多JQueryUI的外观和感觉。
我尝试了很多替代方案--JQueryUI Dialog,jAlert,jqAlert。
但是,似乎所有这些都没有像原始警报那样以同样的方式同步运行。
I would like to replace the native javascript alert() with my own, so that I would be able to control the theme and have it more JQueryUI look and feel. I've tried numerous alternatives - JQueryUI Dialog, jAlert, jqAlert. However, it appears that all of them not functioning synchronizely in the same fashion like the original alert.
示例:
function mytest()
{
alert('one');
alert('two');
alert('three');
}
在此示例中,使用原始alert(),将出现3个对话框连续一个接一个。但是在替代品中,它们一下子出现了!
In this example, with the original alert(), the 3 dialogs would appear one after the other in a row. But in the substitutes, they appear all at once!
有什么想法吗?
推荐答案
本机 alert()
使浏览器停止停止。您将找不到任何第三方库来执行此操作,因为这是不可能的。*
The native alert()
brings the browser to a dead halt. You will not find any third party libraries that do that, because it's not possible.*
我在一起快速演示如何使用单个jQuery对话框而不是警报。
I threw together a quick demo of how you can use a single jQuery dialog instead of an alert.
var alertManager = (function() {
var _queue = [],
_opts = {
modal: true,
autoOpen: false,
buttons: {
OK: function ()
{
$(this).dialog('close');
var next = _queue.shift();
if (typeof next === 'string')
{
_dialog.text(next).dialog('open');
}
}
}
},
_dialog = $('<div id="alertDialog" title="Alert!"></div>').dialog(_opts),
_self = {};
_self.show = function (message) {
if (_dialog.dialog('isOpen')) {
_queue.push(String(message));
}
else {
_dialog.text(message).dialog('open');
}
}
return _self;
}());
$('#clicky').click(function ()
{
alertManager.show('alert numero uno');
alertManager.show('alert #2');
alertManager.show({foo: 'bar'});
alertManager.show(document.getElementById('clicky'));
alertManager.show('last one');
});
这里的热门演示动作&#x2192;
你也可以很容易地把它变成一个jQuery插件。
Hot demo action over here →
You could also turn this into a jQuery plugin pretty easily.
*虽然您可以使用伪造它,而
循环旋转时对话框已打开。我不推荐这个。
*though you could fake it with a while
loop that spins while the dialog is open. I do not recommend this.
这篇关于任何JQuery alert()替换JavaScript的本机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!