任何JQuery alert()替换JavaScript的本机?

我想用我自己的替换本机javascript alert(),这样我就可以控制主题并让它具有更多的JQueryUI外观和感觉。 我尝试了很多替代方案–JQueryUI Dialog,jAlert,jqAlert。 然而,似乎所有这些都不像原始警报那样以同样的方式同步运行。

例:

function mytest() { alert('one'); alert('two'); alert('three'); } 

在此示例中,使用原始alert(),3个对话框将一个接一个地显示在一行中。 但在替代品中,它们同时出现!

任何的想法?

本机alert()使浏览器停止运行。 您将找不到任何第三方库,因为这是不可能的。*


编辑

我汇总了一个快速演示,说明如何使用单个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 = $('
').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'); });

热门演示动作在这里→

你也可以很容易地把它变成一个jQuery插件。


*虽然您可以在对话框打开时使用while循环伪造它。 推荐这个。

我很久以前找到了一个库来解决这个问题的警报,提示和确认,这很容易使用:

在这里演示: http : //labs.abeautifulsite.net/archived/jquery-alerts/demo/

 // Usage: // jAlert( message, [title, callback] ) // jConfirm( message, [title, callback] ) // jPrompt( message, [value, title, callback] ) 

在这里下载: http : //labs.abeautifulsite.net/archived/jquery-alerts/jquery.alerts-1.1.zip

一个jquery警报:

  JQuery.fn.alert = function(message) { alert(message); }; 

使用示例:

  $("#item1").alert("hello"); 

我的天啊:D

jquery只是一个DOM框架。 这不是其他的javascript! jquery只是一些javascript行。 而不是取代javascript。

如果你想创建一个对话框,那么我建议你搜索jquery插件。

http://choosedaily.com/1178/15-jquery-popup-modal-dialog-plugins-tutorials/

如果您正在寻找替代行为,您可能需要尝试: http : //plugins.jquery.com/project/freeow

它还提醒用户,但不会锁定浏览器,因为“马特球”说

您可以使用jQueryUI对话框轻松模仿常规js警报的同步性。 只需使用提供的事件 – 在这种情况下, close ,在关闭对话框时调用:

 
Dialog
Another dialog
$("#dialog").dialog({ close: function(event, ui) { $("#dialog2").dialog(); } });

现在,当您关闭第一个对话框时,第二个对话框将打开。

你可以使用并完美地控制这个ui对话框http://jqueryui.com/demos/dialog/

只需在需要时唤起它们。

如何分层警报?
它们仍会一下子出现,但是用户只能看到第一个,直到她关闭它,然后第二个出现(显示)等等。
– 可以通过更新“全局”last-z-index变量轻松实现。

与此同时,我最近还创建了一个新function,允许使用jqueryui对话框确认框。

它非常易于使用

 dlgConfirm('Are you sure you want to cancel this change-email request? 
', 'Cancel Email Change', 'Continue', function(dlg){ //do ajax or something return false; //do not close dialog until ajax is complete } dlgConfirm('Are you sure you want to submit this form', function(dlg){ $('form', dlg).submit(); return true; });

这是源代码(公共域):

  

DAlert jQuery UI插件试试这个:andrewdex.github.io/dalert