【问题标题】:How to hide button on the Jquery UI dialog box [duplicate]如何隐藏Jquery UI对话框上的按钮[重复]
【发布时间】:2011-10-15 02:26:28
【问题描述】:

我一直在使用 JQuery UI 对话框。我正在使用以下代码。谁能告诉我点击后如何隐藏导出按钮

$( "#dialog-confirm1" ).dialog({
            resizable: false,
            height:350,
            width:650,
            modal: false,
            autoOpen:false,
            buttons: {
                "Export": function() {
                    exportCSV(2);


                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

【问题讨论】:

  • 当你说“隐藏导出按钮”时,你的意思是让对话框保持打开状态,只有取消按钮?

标签: javascript jquery user-interface dialog


【解决方案1】:

你可以使用$('.ui-button:contains(Export)').hide():(下面的代码在你点击时隐藏了导出按钮)

$( "#dialog-confirm1" ).dialog({
            resizable: false,
            height:350,
            width:650,
            modal: false,
            autoOpen:false,
            buttons: {
                "Export": function() {
                    exportCSV(2);
                    $(event.target).hide();


                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

【讨论】:

  • 嗨,Nicola 谢谢,它可以工作。但忘了告诉。我确实有两个对话框 dialog-confirm1 和 dialog-confirm0 并且都有“导出”按钮,当我单击对话框的导出按钮时 - Confirm1 对话框,它还隐藏了对话框确认对话框的导出按钮。谢谢,Ravi
  • @Ravi 我认为更好的选择是 Frédéric Hamidi 指出的,使用 event.target(我更新了我的答案以使用它)
  • event.target 转到按钮内部的跨度,而不是按钮本身。使用:$(event.target).parent().hide();而是。
【解决方案2】:

buttons 选项的 documentation 表示:

回调的上下文是对话框元素;如果您需要访问权限 到按钮,它可以作为事件对象的目标。

因此,您可以使用event.target 来引用按钮元素:

buttons: {
    "Export": function(event) {
        $(event.target).hide();
        exportCSV(2);
    },
    "Cancel": function() {
        $(this).dialog("close");
    }
}

【讨论】:

  • 使用 $(event.target).parent().hide();反而。至少对我来说,目标是按钮内的跨度。
【解决方案3】:
buttons: [{
    "Export": function() { exportCSV(2); },
    click: $( this ).hide()

}]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 2016-04-13
    • 2010-10-28
    • 2011-04-18
    • 2011-10-05
    相关资源
    最近更新 更多