如何启用jquery ui按钮

时间:2012-10-30 11:37:10

标签: javascript jquery jquery-ui

我正在使用jquery ui对话框。在对话框中我有1个保存按钮,当用户点击保存按钮回调中的保存按钮时,我将其禁用。我的代码:

$("#Form1").dialog({
    width: 500, autoOpen: false, modal: true, resizable: false, draggable: false,
    buttons: {
        "Save": function (event, ui) {
            $(event.currentTarget).button({ disabled: true });
             ... .
             ....
         }
    }
    , beforeClose: function () {
        //here how can i enable the save button
    }
});

现在我的问题是,当用户再次打开对话框时,保存按钮仍然处于禁用状态,因此我想在对话框beforeClose事件中启用按钮。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

您调用对话框的元素将被包装在父级中,因此可以添加标题栏,按钮等。所有按钮都有类ui-button

这应该做你需要的事情

beforeClose:function(){
   $(this).parent().find('.ui-button').button({ disabled: false });

}

答案 1 :(得分:0)

您可能会发现以下列方式启用和禁用按钮更容易:

btn_save = $('#Form1').parent().find(':button:contains("save")');

//disable the save button
$(btn_save).prop('disabled', true).addClass('ui-state-disabled');

//enable the save button
$(btn_save).prop('disabled', false).removeClass('ui-state-disabled');

添加的css类将为按钮提供禁用的css样式。另请注意,:contains选择器区分大小写。