简体   繁体   English

jQuery UI模式对话框:不显示按钮图标

[英]jQuery UI modal dialog: button icons do not appear

My modal dialog works perfectly (meaning I can adjust every option), except that the button icons option has no effect. 我的模态对话框完美运行(意味着我可以调整每个选项),但按钮图标选项无效。 Here's the code I'm using to generate the dialog: 这是我用来生成对话框的代码:

$('#alert_div')
    .attr("title", "Delete all instances?")
    .text("Are you sure you want to delete all instances of this event between the specificed dates?  This cannot be undone.")
    .dialog({
        modal: true,
        draggable: false,
        position: { my: "top", at: "center", of: window },
        buttons: [
            {
                text: "No",
                icons: { primary: "ui-icon-check" },
                click: function() {
                    $(this).dialog('close');
                    console.log('Clicked no.');
                }
            },
            {
                text: "Yes",
                click: function () {
                    $(this).dialog('close');
                    console.log('Clicked yes');
                }
            }
        ]
    });

I've looked at every relevant Stack Overflow question I could find – eg this one . 我已经查看了我能找到的每个相关Stack Overflow问题 - 例如这个问题 Aside from attaching an element to the button on open, I don't know how to solve this. 除了在打开时将元素附加到按钮,我不知道如何解决这个问题。 When I create elements elsewhere in the document and give them the proper class, the icons show up properly. 当我在文档中的其他位置创建元素并为它们提供正确的类时,图标会正确显示。

Here's the HTML jQuery generates for the button when the dialog is opened: 这是打开对话框时为按钮生成的HTML jQuery:

<div class="ui-dialog-buttonset"><button type="button" icons="[object Object]" class="ui-button ui-corner-all ui-widget">OK</button></div>

I'm assuming there should be something other than '[object Object] in the icons attribute. 我假设在icons属性中应该有'[object Object]以外的东西。 Why is this happening? 为什么会这样? I'm using jQuery UI v. 1.12.0 and jQuery v. 3.0.0., and I'm not using Bootstrap. 我正在使用jQuery UI v.1.12.0和jQuery v.3.0.0。而且我没有使用Bootstrap。

Apparently, the problem is a bug in jquery-ui 1.12.0. 显然,问题是jquery-ui 1.12.0中的一个错误。 If you substitute 1.11.4 for 1.12.0 in your fiddle, the problem goes away. 如果你在小提琴中用1.11.4代替1.12.0,问题就会消失。

I ran your code (the code you published above, not the code in your fiddle) in my own test environment, and everything worked fine. 我在自己的测试环境中运行了你的代码(你上面发布的代码,而不是你小提琴中的代码),一切正常。 (I downloaded 1.11.4 in May, when it was the latest stable version.) It seems that the button() method isn't getting called when dialog() is called. (我在5月下载了1.11.4,当时它是最新的稳定版本。)看来调用dialog()时没有调用button()方法。 As you correctly surmise, there shouldn't be an object Object in the icons element. 正如你猜测的那样,在icons元素中不应该有一个object Object My button code looks like this: 我的按钮代码如下所示:

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icons" role="button">
    <span class="ui-button-icon-primary ui-icon ui-icon-check"></span>
    <span class="ui-button-text">No</span>
    <span class="ui-button-icon-secondary ui-icon ui-icon-circle-check"></span>
</button>

Looks like maybe this is a "real genuine bug" in jQuery-UI 1.12.0. 看起来这可能是jQuery-UI 1.12.0中的“真正的真正的bug”。 :) :)

Edit: looks like actually this is a "real genuine feature" in jQuery-UI 1.12.0, along with a host of other changes, some of which break compatibility with previous versions. 编辑:看起来实际上这是jQuery-UI 1.12.0中的“真正的真正功能”,以及许多其他更改,其中一些更改与先前版本的兼容性。 See Harpo's "new syntax" link. 请参阅Harpo的“新语法”链接。 Anyone using menus (especially menus, old ones will no longer work), radiobuttons/checkboxes, or a few other things, will want to read it. 任何人使用菜单(特别是菜单,旧的菜单将不再工作),radiobuttons /复选框或其他一些东西,都会想要阅读它。

As for getting two icons on a button, it's still possible with the new syntax, but you can't do it using the buttons parameter in the dialog() method. 至于在按钮上获取两个图标,仍然可以使用新语法,但是不能使用dialog()方法中的buttons参数来完成。 Instead, you'll have to do the button the standard way, adding spans for the icons. 相反,您必须以标准方式执行按钮,为图标添加跨度。 (The upgrade doc says that you can just put the second icon span in the markup, and use the icon parameter for what used to be the primary icon, but I wasn't able to get that to work in this context.) So, for the markup: (升级文档说您可以将第二个图标跨度放在标记中,并使用icon参数作为主要图标,但我无法在此上下文中使用它。)所以,对于标记:

<div id="alert_div">
    <button id="okButton">
        <span class="ui-icon ui-icon-check"></span>
        Ok
        <span class="ui-icon ui-icon-circle-check"></span>
    </button>
</div>

And then: 接着:

$('#alert_div').dialog({
    open: function(e, ui) {
        $('#okButton')
        .button()
        .on('click', function() {
            $(this).dialog('close');
        });
    }
});

jQuery UI 1.12 introduced a new syntax for button icons , which I have confirmed fixes this problem (see this jsFiddle ). jQuery UI 1.12 为按钮图标引入了一种新语法 ,我已经确认修复了这个问题(请参阅此jsFiddle )。 Currently, it doesn't accept the deprecated options; 目前,它不接受已弃用的选项; a PR has been submitted to fix that. 已提交PR以解决此问题。 See my bug report for details. 有关详情,请参阅我的错误报告 The following code works with jQuery UI 1.12 and jQuery 3.1.0: 以下代码适用于jQuery UI 1.12和jQuery 3.1.0:

$("#alert_div")
.attr("title", "Error")
.text("Please choose a calendar and enter both start and end dates.")
.dialog({
    modal: true,
    draggable: false,
    resizable: false,
    position: { my: "top", at: "top", of: window },
    buttons: [{
        text: "OK",
        icon: "ui-icon-check",
        click: function() {
            $(this).dialog("close");
        }
    }]
});

请看看这是例如,我们可以做任何事情..

Please have a look this is for Example, we can do any thing to it.. 请看看这是例如,我们可以做任何事情..

use style to make changes into it... 使用样式对其进行更改...

Thanks... :) 谢谢... :)

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

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