[英]alert like function in javascript
我想在javascript中创建模式弹出窗口。
但是我的要求是,每当弹出窗口打开时,它将停止执行下一个javascript行,直到关闭为止。
例如
var bool = false;
DisplayModal("Show Message");
bool = true;
alert("alerted only after closing the pop up : bool = true");
bool = false;
因此,直到我关闭"Show Message"
的模式弹出框,布尔值才会为真。 当我关闭弹出窗口时,其余的脚本将在DisplayModal
之后按顺序运行...
同样,就像alert
但我不想覆盖alert
..
我需要一些帮助,在此先感谢...
编辑:
尝试解释更多..
我想在DisplayModal
调用时停止执行
停止执行
之后弹出窗口显示
弹出窗口关闭后,从下一行继续(意味着: bool = true; ...
)
如果要自定义对话框的外观,可以使用jQuery的对话框小部件。 它支持事件。 我举了一个简单的例子: http : //jsfiddle.net/5CBdm/
您可以将事件处理程序附加到对话框的close事件,并将其余代码放入事件处理程序中。
所需的HTML:
<div id="dialog-modal" title="Modal dialog">
<p>Message</p>
</div>
以及相应的Javascript:
$("#dialog-modal").dialog({
height: 140,
modal: true,
close: function (event, ui) {
alert("Executed when the dialog is closed.");
}
});
链接到对话框:
您可以使用jQuery插件。 例如http://dimsemenov.com/plugins/magnific-popup/
或者,您也可以自己制作(在jsfiddle上尝试: http : //jsfiddle.net/T2Vn3/ ):
<div class="overlay">
<div class="alert">
This is alert!
<br/>
<button>OK</button>
</div>
</div>
<button class="forAlert">Click me!</button>
JS:
document.querySelector('.alert button').addEventListener('click', function () {
document.querySelector('.overlay').style.display = 'none';
}, false);
document.querySelector('.forAlert').addEventListener('click', function () {
document.querySelector('.overlay').style.display = 'block';
});
听起来像是需要confirm
的工作
(function() {
var result = confirm("I'm Happy?");
alert(result ? "Yes, I'm happy" : "No, I'm not happy");
}());
确认将阻止当前执行线程,直到返回结果
alert,提示,确认和XMLHTTPRequest是JavaScript中唯一的同步功能。 您必须使用事件和回调。
如果您希望用户在关闭弹出窗口之前不能执行任何操作,则可以使透明div恢复所有页面(弹出窗口除外)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.