我知道我可以拨打alert('Warning1');alert('Warning2');
,它会显示2个提醒。但是,当我使用JAlert Page中提到的JAlert插件时,我无法显示多个警报消息。你们有没有使用过这个插件并解决了相同的问题?如何多次显示'JAlert'弹出窗口?
回答
右对齐,所以我做了一个样本HTML和测试这个东西出来
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<!-- Dependencies -->
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery-ui.min.js" type="text/javascript"></script>
<!-- Core files -->
<script src="jquery.alerts.js" type="text/javascript"></script>
<link href="jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
$(document).ready(function() {
jAlert('This is a custom alert box', 'Alert Dialog', doAlert() );
function doAlert() {
alert('CallBack')
}
});
</script>
</head>
<body>
</body>
因此,基于从网站docuemntation
使用 这个插件利用$ .alerts命名空间,但是有三个内置的快捷功能>使执行更容易:
jAlert(message,[title,callback])
现在好了,这是jQuery的
- 文件准备启动的逻辑
- jAlert显示自定义框及认定中应尽快做回调doAlert()
- 作为第一jAlert clsoes它会做回调,并打开jALert
实际发生的
的另一个实例10- 的功能doAlert实际jAlert之前大火被调用回调
- 第一jAlert触发OK!但没有显示出来,因为已经有一个jAlert isntance和仅仅指刚忽略不管发生什么事
总之
此插件无法在内部处理多个呼叫,回调是错误的!因为他并没有叫回来,但调用一个函数调用自身或等待inital jAlert被接受
解决方案
- 找到另一个插件
- 之前创建一个内部的JScript排队系统。不知何故基于这个插件工作有多可怕
为什么alert();那么工作??!?!?!?!?
因为当您拨打alert();
代码执行STOPS并等待,直到您按OK并继续代码。
所以我很抱歉地说,但这个插件运行不正常,我建议你找到另一个也许。
我会尝试做一些代码来做你需要的。但现在我不确定。 – ppumkin 2011-05-04 20:30:08
谢谢。要找到另一个插件。 – 2011-05-05 06:29:35
我有同样的问题,并像这样解决它: 在jquery.alerts。JS,只是为公共职能的意见之前,我已经插入这样的:
raiseNextDialog: function() {
$.alerts.callIsActive = false;
if ($.alerts.waitingCalls.length>0) {
var params = $.alerts.waitingCalls.shift();
$.alerts._show(params[0], params[1], params[2], params[3], params[4]);
}
},
dialogShallWait: function (title, msg, value, type, callback) {
if ($.alerts.callIsActive) {
$.alerts.waitingCalls.push([title, msg, value, type, callback]);
return true; // can't show now
} else {
$.alerts.callIsActive = true;
return false;
}
},
的想法是,如果先前的对话仍然是开放的,我们按这个唤到数组,在关闭对话框中使用。
现在,我们还需要添加一行到_show()函数的开头:
if ($.alerts.dialogShallWait(title, msg, value, type, callback)) return;
而且为五。点击()处理,我们需要调用回调后,加入这行:
$.alerts.raiseNextDialog();
就这样!
我想更新创建者,但没有办法在他的网站上发表评论... 而我正在使用使用标准主题演示的精彩版本here。太好了!
我也面临同样的问题,我的客户请求一个提醒框提醒会话时间,然后5分钟后,另一个提醒框过期会话。开发人员已将jAlert用于所有警报框,所以我也使用它。我试过了,但是你的代码没有工作,我认为raiseNextDialog()方法有问题,因为第二个警报只在短时间内出现并立即关闭。为了节省时间,我用一个简单的解决方案来解决我的情况,通过使用一些标志:)。不管怎样,谢谢。 – 2012-03-07 04:14:27
上一个答案部分正确,但未能定义包含多个警报的数组($ .alerts.waitingCalls)。下面的代码替换整个jquery.alerts.js(整个包,请访问:http://code.google.com/p/jalert-plus/downloads/list)
// jQuery Alert Dialogs Plugin
//
// Version 1.1 (extended)
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Mike Walters
// 27 December 2011
// http://code.google.com/p/jalert-plus/downloads/list
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
// jAlert(message, [title, callback])
// jConfirm(message, [title, callback])
// jPrompt(message, [value, title, callback])
//
// History:
//
// 1.00 - Released (29 December 2008)
//
// 1.01 - Fixed bug where unbinding would destroy all resize events
//
// DECEMBER 2011 - added ability to popup multiple alerts (mike walters)
//
// License:
//
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC.
//
(function($) {
$.alerts = {
// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
verticalOffset: -75, // vertical offset of the dialog from center screen, in pixels
horizontalOffset: 0, // horizontal offset of the dialog from center screen, in pixels/
repositionOnResize: true, // re-centers the dialog on window resize
overlayOpacity: .01, // transparency level of overlay
overlayColor: '#FFF', // base color of overlay
draggable: true, // make the dialogs draggable (requires UI Draggables plugin)
okButton: ' OK ', // text for the OK button
cancelButton: ' Cancel ', // text for the Cancel button
dialogClass: null, // if specified, this class will be applied to all dialogs
waitingCalls: new Array(),
raiseNextDialog: function() {
$.alerts.callIsActive = false;
if ($.alerts.waitingCalls.length>0) {
var params = $.alerts.waitingCalls.shift();
$.alerts._show(params[0], params[1], params[2], params[3], params[4]);
}
},
dialogShallWait: function (title, msg, value, type, callback) {
if ($.alerts.callIsActive) {
$.alerts.waitingCalls.push([title, msg, value, type, callback]);
return true; // can't show now
} else {
$.alerts.callIsActive = true;
return false;
}
},
// Public methods
alert: function(message, title, callback) {
if(title == null) title = 'Alert';
$.alerts._show(title, message, null, 'alert', function(result) {
if(callback) callback(result);
});
},
confirm: function(message, title, callback) {
if(title == null) title = 'Confirm';
$.alerts._show(title, message, null, 'confirm', function(result) {
if(callback) callback(result);
});
},
prompt: function(message, value, title, callback) {
if(title == null) title = 'Prompt';
$.alerts._show(title, message, value, 'prompt', function(result) {
if(callback) callback(result);
});
},
// Private methods
_show: function(title, msg, value, type, callback) {
if ($.alerts.dialogShallWait(title, msg, value, type, callback)) return;
$.alerts._hide();
$.alerts._overlay('show');
$("BODY").append(
'<div id="popup_container">' +
'<h1 id="popup_title"></h1>' +
'<div id="popup_content">' +
'<div id="popup_message"></div>' +
'</div>' +
'</div>');
if($.alerts.dialogClass) $("#popup_container").addClass($.alerts.dialogClass);
// IE6 Fix
var pos = ($.browser.msie && parseInt($.browser.version) <= 6) ? 'absolute' : 'fixed';
$("#popup_container").css({
position: pos,
zIndex: 99999,
padding: 0,
margin: 0
});
$("#popup_title").text(title);
$("#popup_content").addClass(type);
$("#popup_message").text(msg);
$("#popup_message").html($("#popup_message").text().replace(/\n/g, '<br />'));
$("#popup_container").css({
minWidth: $("#popup_container").outerWidth(),
maxWidth: $("#popup_container").outerWidth()
});
$.alerts._reposition();
$.alerts._maintainPosition(true);
switch(type) {
case 'alert':
$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
$("#popup_ok").click(function() {
$.alerts._hide();
callback(true);
$.alerts.raiseNextDialog();
});
$("#popup_ok").focus().keypress(function(e) {
if(e.keyCode == 13 || e.keyCode == 27) $("#popup_ok").trigger('click');
});
break;
case 'confirm':
$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
$("#popup_ok").click(function() {
$.alerts._hide();
if(callback) callback(true);
$.alerts.raiseNextDialog();
});
$("#popup_cancel").click(function() {
$.alerts._hide();
if(callback) callback(false);
$.alerts.raiseNextDialog();
});
$("#popup_ok").focus();
$("#popup_ok, #popup_cancel").keypress(function(e) {
if(e.keyCode == 13) $("#popup_ok").trigger('click');
if(e.keyCode == 27) $("#popup_cancel").trigger('click');
});
break;
case 'prompt':
$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
$("#popup_prompt").width($("#popup_message").width());
$("#popup_ok").click(function() {
var val = $("#popup_prompt").val();
$.alerts._hide();
if(callback) callback(val);
$.alerts.raiseNextDialog();
});
$("#popup_cancel").click(function() {
$.alerts._hide();
if(callback) callback(null);
$.alerts.raiseNextDialog();
});
$("#popup_prompt, #popup_ok, #popup_cancel").keypress(function(e) {
if(e.keyCode == 13) $("#popup_ok").trigger('click');
if(e.keyCode == 27) $("#popup_cancel").trigger('click');
});
if(value) $("#popup_prompt").val(value);
$("#popup_prompt").focus().select();
break;
}
// Make draggable
if($.alerts.draggable) {
try {
$("#popup_container").draggable({ handle: $("#popup_title") });
$("#popup_title").css({ cursor: 'move' });
} catch(e) { /* requires jQuery UI draggables */ }
}
},
_hide: function() {
$("#popup_container").remove();
$.alerts._overlay('hide');
$.alerts._maintainPosition(false);
},
_overlay: function(status) {
switch(status) {
case 'show':
$.alerts._overlay('hide');
$("BODY").append('<div id="popup_overlay"></div>');
$("#popup_overlay").css({
position: 'absolute',
zIndex: 99998,
top: '0px',
left: '0px',
width: '100%',
height: $(document).height(),
background: $.alerts.overlayColor,
opacity: $.alerts.overlayOpacity
});
break;
case 'hide':
$("#popup_overlay").remove();
break;
}
},
_reposition: function() {
var top = (($(window).height()/2) - ($("#popup_container").outerHeight()/2)) + $.alerts.verticalOffset;
var left = (($(window).width()/2) - ($("#popup_container").outerWidth()/2)) + $.alerts.horizontalOffset;
if(top < 0) top = 0;
if(left < 0) left = 0;
// IE6 fix
if($.browser.msie && parseInt($.browser.version) <= 6) top = top + $(window).scrollTop();
$("#popup_container").css({
top: top + 'px',
left: left + 'px'
});
$("#popup_overlay").height($(document).height());
},
_maintainPosition: function(status) {
if($.alerts.repositionOnResize) {
switch(status) {
case true:
$(window).bind('resize', $.alerts._reposition);
break;
case false:
$(window).unbind('resize', $.alerts._reposition);
break;
}
}
}
}
// Shortuct functions
jAlert = function(message, title, callback) {
$.alerts.alert(message, title, callback);
}
jConfirm = function(message, title, callback) {
$.alerts.confirm(message, title, callback);
};
jPrompt = function(message, value, title, callback) {
$.alerts.prompt(message, value, title, callback);
};
})(jQuery);
- 1. 如何显示其他弹出窗口上的弹出窗口?
- 2. JQuery - 仅显示弹出窗口一次
- 3. 一次显示一个弹出窗口
- 4. 如何显示弹出窗口?
- 5. 如何显示弹出窗口
- 6. 如何显示弹出窗口?
- 7. 弹出窗口不显示
- 8. 弹出窗口不显示
- 9. 显示弹出窗口
- 10. iPhone:MKAnnotation显示弹出窗口?
- 11. 如何使JavaScript中的弹出窗口只显示一次?
- 12. Oracle Forms弹出窗口多次出现
- 13. asp.net - 弹出窗口显示弹出窗口
- 14. 如何仅在窗口范围内显示弹出窗口?
- 15. 如何在父窗口顶部显示弹出窗口?
- 16. 如何在我的主窗口中显示弹出窗口?
- 17. 如何显示传单标记的许多弹出窗口
- 18. 在c#中显示弹出窗口.net
- 19. 在弹出窗口中显示viewpager
- 20. 显示一个模态弹出窗口
- 21. HTML弹出窗口不显示
- 22. 在弹出窗口中显示html
- 23. 在弹出窗口中显示结果
- 24. 使用Fancybox显示弹出窗口div
- 25. Android Webview不显示弹出窗口
- 26. 在webgrid中显示弹出窗口
- 27. 在Python中显示弹出窗口(PyQt4)
- 28. 显示CD的弹出窗口
- 29. Bootstrap Modal弹出窗口不显示
- 30. iPad:显示帮助弹出窗口?
您链接到了错误的插件...它是关于上下文菜单。 – 2011-05-02 13:13:58
http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/ – ppumkin 2011-05-02 13:19:30
你想同时显示2个提醒吗?还是一个接一个? – ppumkin 2011-05-02 13:19:45