0

有人可以帮我隐藏/禁用jQuery对话框上的按钮吗?

场景:单击按钮时,我正在打开一个带有“添加”和“更新”按钮的对话框。在对话框中,我有 2 个包含日期和消息的文本框。如果数据库中已经存在数据,则两者都将填充数据,否则它们将为空白,允许用户添加数据。

现在,如果文本框有预填充的数据(消息存在于 db 中)我必须隐藏添加按钮,因为用户只能更新消息。我尝试了一些从 stackoverflow 获得的技巧,但在我打开对话框时它们都没有工作按钮单击框,所以我想我正在动态创建按钮,我无法即时隐藏它们。

我还尝试为对话框按钮提供一个 ID 并使用以下代码隐藏/禁用它: $('#id').hide(); $('#id').attr('disabled','disabled');

我查看了下面的小提琴,这正是我想要的,但如果我采用这个,那么我必须做很多代码更改。所以,想知道是否有人可以为我提供一个简单的解决方案。

[http://jsfiddle.net/kkh2a/1/]

提前致谢。

    $('#dialog-form').dialog({width:350,height:300,
    resizable:false,
    modal:true,
    closeOnEscape: true,
    draggable:false,
    show:{effect:"fade"},
    buttons:{
        Add:{
            text:'Add',
            id:'AddMsg',
            click:function(){

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

2 回答 2

0

Hy all, I use this way:

$("#myDivForLoadingDialog").dialog({
    modal: true,
    resizable: false,
    height: "auto",
    draggable: false,
    closeOnEscape: false,
    open: function (event, ui) {
        $("#myDivForLoadingDialog").prev().hide();
    }
})

without setting button in the option it does not show any button inside

set closeOnEscape: false to avoid your loading message been closed by "esc" button

in the opencallback hide alle the title box (and the close button it has inside).

I prefer to avoid drag, resize and all features not needed by loading message.

it works with jQuery 1.11.1 (and maybe with all previous version)

于 2014-09-08T13:54:25.050 回答
0

尝试这个:

$('#dialog-form').dialog({
    ...
    buttons : {...},
    open : function() {
        $('#dialog-form')
            .dialog('widget')
            .find('div.ui-dialog-buttonpane div.ui-dialog-buttonset button')
                .eq(0)
                .button('disable');
    }
});
于 2013-07-12T15:54:14.113 回答