简体   繁体   English

如何在对话框加载时隐藏jQuery对话框按钮?

[英]How to hide a jquery dialog button on dialog load?

Can someone please help me with hiding/disabling a button on jQuery dialog box? 有人可以帮我隐藏/禁用jQuery对话框上的按钮吗?

Scenario: On button click I am opening a dialog box with 'Add' and 'Update' button. 场景:在按钮上单击“我正在使用“添加”和“更新”按钮打开一个对话框。 Inside the dialog I have 2 text box containing date and message.Both will populate data if data already present in database else they will be blank allowing user to add data. 在对话框中,我有2个包含日期和消息的文本框。如果数据库中已经存在数据,则两者都将填充数据,否则将为空以允许用户添加数据。

Now, If text box has pre-populated data(message exist in db) I have to hide Add button as user can only update the message.I tried few tricks which I got from stackoverflow but none of them is working as I am opening dialog box on button click so I guess I am creating button dynamically and I cannot hide them on fly. 现在,如果文本框具有预先填充的数据(db中存在消息),则必须隐藏``添加''按钮,因为用户只能更新消息。我尝试了一些从stackoverflow获得的技巧,但是当我打开对话框时它们都没有起作用单击按钮上的框,所以我想我正在动态创建按钮,但无法即时隐藏它们。

I also tried giving an id to dialog button and hiding/disabling it using below code: $('#id').hide(); 我还尝试为对话框按钮提供一个ID,并使用以下代码隐藏/禁用它:$('#id')。hide(); $('#id').attr('disabled','disabled'); $('#id')。attr('disabled','disabled');

I looked into the below fiddle which is exactly what I want but If I adopt this then I have to make a lot of code change. 我看了下面的小提琴,这正是我想要的,但是如果我采用了这个小提琴,那么我必须进行很多代码更改。 So, was wondering if anyone can provide me an easy solution. 因此,想知道是否有人可以为我提供简单的解决方案。

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

Thanks in advance. 提前致谢。

    $('#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");
        }
    }});

Try this: 尝试这个:

$('#dialog-form').dialog({
    ...
    buttons : {...},
    open : function() {
        $('#dialog-form')
            .dialog('widget')
            .find('div.ui-dialog-buttonpane div.ui-dialog-buttonset button')
                .eq(0)
                .button('disable');
    }
});

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 设置closeOnEscape:false以避免您的加载消息被“ esc”按钮关闭

in the opencallback hide alle the title box (and the close button it has inside). 在opencallback中隐藏标题框(及其内部的关闭按钮)。

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) 它适用于jQuery 1.11.1(也许适用于所有以前的版本)

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

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