创建看起来更严重的 jQuery 错误对话框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4016163/
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-08-26 16:30:42  来源:igfitidea点击:

Create more serious looking jQuery error dialog?

jqueryjquery-uimodal-dialogjquery-ui-dialog

提问by Marcus Leon

Is there a jQuery UI class you can use to create a more severe looking error dialog box than the one below?

是否有一个 jQuery UI 类可以用来创建一个比下面的更严重的错误对话框?

alt text

替代文字

This is the HTML we use to create the dialog:

这是我们用来创建对话框的 HTML:

<div style="display:none" id="div-dialog-warning">
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><div/></p>
</div>

And this is how we show it:

这就是我们展示它的方式:

$("#div-dialog-warning").dialog({
    title: t,
    resizable: false,
    height: 160,
    modal: true,
    buttons: {
        "Ok" : function () {
            $(this).dialog("close");
        }
    }
});

回答by Nick Craver

You can add the ui-state-errorclass that comes in your theme, like this:

您可以添加ui-state-error主题中的类,如下所示:

$("#div-dialog-warning").dialog({
    title: t,
    resizable: false,
    height: 160,
    modal: true,
    buttons: {
        "Ok" : function () {
            $(this).dialog("close");
        }
    }
}).parent().addClass("ui-state-error");

Since the dialog gets wrapped we're using .parent()to get the container including the titlebar. Your theme looks like flickso here's a demo showing that theme in action.

由于对话框被包装,我们.parent()用来获取包含标题栏的容器。您的主题看起来像轻弹,所以这里有一个演示,展示了该主题的实际效果

回答by Gabriel Ryan Nahmias

I know this is old but, actually, it would be more suitable to use the built-in "dialogClass" option, like so:

我知道这很旧,但实际上,使用内置的“dialogClass”选项更合适,如下所示:

$("#div-dialog-warning").dialog( {
    buttons: {
        "Ok" : function () {
            $(this).dialog("close");
        }
    },
    dialogClass: "error",
    height: 160,
    modal: true,
    resizable: false,
    title: t
} );

回答by Iman

use this excellent and simple jquery notification and alert plugin

使用这个优秀而简单的 jquery 通知和警报插件

ned.im/noty

ned.im/noty

in the demo folder there is a modal sample

在演示文件夹中有一个模态示例

NOTY is a jQuery plugin that makes it easy to create alert - success - error - warning - information - confirmation messages as an alternative the standard alert dialog. Each notification is added to a queue.

NOTY 是一个 jQuery 插件,它可以轻松创建警报 - 成功 - 错误 - 警告 - 信息 - 确认消息作为标准警报对话框的替代方案。每个通知都被添加到一个队列中。

回答by Delta

dialogClassis deprecated in v1.12 of jQuery (http://api.jqueryui.com/dialog/#option-dialogClass)

dialogClass在 jQuery ( http://api.jqueryui.com/dialog/#option-dialogClass) 的v1.12 中已弃用

Use classesinstead (http://api.jqueryui.com/dialog/#option-classes)

使用classes替代(http://api.jqueryui.com/dialog/#option-classes

So for >= v1.12 would be:

所以对于 >= v1.12 将是:

$("#div-dialog-warning").dialog({
    title: t,
    resizable: false,
    height: 160,
    modal: true,
    classes: {
        "ui-dialog": "ui-state-error"
    },
    buttons: {
        "Ok" : function () {
            $(this).dialog("close");
        }
    }
});

Take a look at http://api.jqueryui.com/dialog/#themingfor all theme able parts

看看http://api.jqueryui.com/dialog/#theming的所有主题部分

and http://api.jqueryui.com/theming/css-framework/for all css classes.

http://api.jqueryui.com/theming/css-framework/适用于所有 css 类。

(Don't include the . (dot) in the value string)

(不要在值字符串中包含 .(点))