javascript 如何隐藏 Jquery UI 对话框上的按钮

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

How to hide button on the Jquery UI dialog box

javascriptjqueryuser-interfacedialog

提问by Ravi Bhartiya

I have been using JQuery UI dialog box.The following code I am using.Can any one please let me know how to hide the Export button after click

我一直在使用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" );
                }
            }
        });

回答by Nicola Peluchetti

You could use $('.ui-button:contains(Export)').hide(): (the following code hides the export button when you click it)

您可以使用$('.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" );
                }
            }
        });

回答by Frédéric Hamidi

The documentationfor the buttonsoption says:

文档buttons选项是说:

The context of the callback is the dialog element; if you need access to the button, it is available as the target of the event object.

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

Therefore, you can use event.targetto refer to the button element:

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

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

回答by Phil

buttons: [{
    "Export": function() { exportCSV(2); },
    click: $( this ).hide()

}]