我想替换原生 JavaScriptalert()
与我自己的,这样我就能够控制主题并拥有更多 JQueryUI 外观和感觉。
我已经尝试了许多替代方案 - JQueryUI Dialog、jAlert、jqAlert。
然而,似乎所有这些都不像原始警报那样以相同的方式同步运行。
Example:
function mytest()
{
alert('one');
alert('two');
alert('three');
}
在这个例子中,与原来的alert()
,这 3 个对话框将连续出现。但在替补席上,却一下子出现了!
任何想法?
当地人alert()
将浏览器带到僵住了。您不会找到任何第三方库可以做到这一点,因为这是不可能的。*
Edit
我整理了一个快速演示,演示如何使用单个 jQuery 对话框而不是警报。
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');
});
热门演示动作在这里 → http://jsfiddle.net/mattball/8zbnf/2/
您还可以轻松地将其变成 jQuery 插件。
*though you could fake it with a while
loop that spins while the dialog is open. I do not recommend this.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)