简体   繁体   English

Javascript中的警报消息

[英]Alert message in Javascript

I am using simple JavaScript code in my PHP code to display an alert message: 我在PHP代码中使用了简单的JavaScript代码来显示警告消息:

<script type="text/javascript">
    window.alert("Can not Send Messages ")
</script>

When the alert message is displayed, the original page disappears, when I press "OK" button in the message box, the original page will appear again. 当显示警告消息时,原始页面消失,当我在消息框中按“确定”按钮时,原始页面将再次出现。 Is there any way to display the error message and to keep the original page in the back? 有什么方法可以显示错误消息并将原始页面保留在背面吗? My other question, is there any way to decorate the message box ^_^ ? 我的另一个问题是,有没有办法装饰消息框^ _ ^?

Thanks and Regards for all. 感谢和问候大家。

alert() blocks until it has been closed. alert()一直阻塞,直到关闭为止。 Simple execute it after the document itself has been loaded: 在文档本身已加载后,只需执行以下操作:

window.onload = function() {
    alert("Cannot send messages");
}

In case you are using something like jQuery you could also use its domready event (it's available without jQuery, too, btw): 如果您使用的是类似jQuery的东西,则还可以使用其domready事件(btw也可以不使用jQuery):

$(document).ready(function() {
    alert("Cannot send messages");
});

Move that script to the end, after your tag. 在标记之后,将该脚本移到末尾。 That way the browser has received enough HTML to construct the page, giving it something to render behind the popup. 这样,浏览器就收到了足够的HTML来构造页面,从而在弹出窗口后呈现了一些内容。

If you want to decorate system "alert" message you can create your own function and replace default. 如果要修饰系统“警报”消息,则可以创建自己的函数并替换默认函数。 But you should be sure that there is no libs that uses default alert, or do the follow: 但是您应该确保没有使用默认警报的库,或者执行以下操作:

// Preserve link to default alert
var defaultAlert= window.alert;

function myAlert(msg, decorate) {
    if (!decorate)  return defaultAlert(msg);

    // Display decorated alert
    // ... draw beauty div
}

window.alert= myAlert;

And that your alert would not pause execution flow like alert do. 而且您的警报不会像警报一样暂停执行流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM