javascript 如何在 php 中使用 jquery 美化警报消息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10926548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:29:54  来源:igfitidea点击:

How to beautify alert msg with jquery in php?

javascriptjqueryuialertviewalert

提问by Frank

I have too many alert msgs according to my programming conditions, and i wants to beautify them coz thatz looking normal and weird.

根据我的编程条件,我有太多的警报消息,我想美化它们,因为它们看起来很正常和奇怪。

if(True)
{
   echo "<script>alert('blah blah blah');</script>";
}

if(False)
{
   echo "<script>alert('blah blah blah');</script>";
}

I tried too many jquery plugins but they work with some specific event like onclcik, onblur, onhover, onload, onsubmit...

我尝试了太多 jquery 插件,但它们可以处理一些特定的事件,例如 onclcik、onblur、onhover、onload、onsubmit...

In above code how can i customize alert msgs without using any event

在上面的代码中,如何在不使用任何事件的情况下自定义警报消息

采纳答案by u283863

You can use jQuery UIfor custom alerts (modal dialogs).

您可以将jQuery UI用于自定义警报(模态对话框)。

Try it here: http://jqueryui.com/demos/dialog/#modal-message

在这里试试:http: //jqueryui.com/demos/dialog/#modal-message

PS: There is no echoin JavaScript.

PS:echoJavaScript 中没有。

enter image description here

在此处输入图片说明

Nice modal dialog!

不错的模态对话框!

Codez:

代码:

$( "#dialog-message" ).dialog({
    modal: true,
    buttons: {
        Ok: function() {
            $( this ).dialog( "close" );
        }
    }
});

回答by nunespascal

Use jQuery UI dialog.

使用 jQuery UI 对话框。

It can be opened directly just like an alert. just write you message to some element like a div, and how it on ready.

它可以像警报一样直接打开。只需将消息写入某个元素,例如 div,以及它如何准备就绪。

See jQuery ui dialog

查看jQuery ui 对话框

Sample code:

示例代码:

js:

js:

<script>
    $(function() {
        $( "#dialog" ).dialog();
    });
    </script>

html:

html:

<div id="dialog" title="My Alert">
    <p>Blah blah blah</p>
</div>

Avoid modal messages if possible. They can be quite irritating, cause your whole screen is locked. Same goes for alerts.

如果可能,避免模态消息。它们可能很烦人,因为你的整个屏幕都被锁定了。警报也是如此。

回答by pbaris

The box that popups when calling alert function, can not be customized through css. It's a browser component so takes the style from the browser and not from the page. So you have to use a popup dialog like jquery ui dialog

调用alert函数时弹出的框,不能通过css自定义。它是一个浏览器组件,因此从浏览器而不是页面中获取样式。所以你必须使用像jquery ui 对话框这样的弹出对话框

回答by Steven

You can try this plugin to beautify alert: http://plugins.jquery.com/alert-beautifier/

你可以试试这个插件来美化警报:http: //plugins.jquery.com/alert-beautifier/