如何通过功能禁用jQuery对话框中的按钮? [英] How can I disable a button in a jQuery dialog from a function?
问题描述
我有一个jQuery对话框,要求用户输入某些信息.在这种形式下,我有一个继续"按钮.我希望只有在所有字段都包含内容后才能启用此继续"按钮,否则它将保持禁用状态.
I have a jQuery dialog that requires the user to enter certain information. In this form, I have a "continue" button. I would like this "continue" button to only be enabled once all the fields have content in them, else it will remain disabled.
我编写了一个函数,每次字段状态更改时都会调用该函数.但是,我不知道如何从此功能启用和禁用对话框按钮.我该怎么办?
I wrote a function that is called everytime a field status has changed. However, I don't know how to enable and disable the dialog button from this function. What should I do?
糟糕,我忘了提到这些按钮的创建过程如下:
Oops and I forgot to mention that these buttons were created as follows:
$(function() {
$("#dialog").dialog({
bgiframe: true,
height: 'auto',
width: 700,
show: 'clip',
hide: 'clip',
modal: true,
buttons: {
'Add to request list': function() {
$(this).dialog('close');
$('form').submit();
},
'Cancel': function() {
$(this).dialog('close');
}
}
})
});
推荐答案
您需要设置禁用的财产
$('#continueButton').attr("disabled", true);
更新:啊哈,我现在看到了复杂性. jQuery对话框的一行将被使用(在按钮"部分下.
Update: Ahha, I see the complexity now. The jQuery Dialog had a single line that will be of use (under the "buttons" section.
var buttons = $('.selector').dialog('option', 'buttons');
您需要从对话框中获取按钮集合,在该对话框中循环查找所需的按钮,然后如上所示设置禁用的属性.
You'll need to get the buttons collection from the dialog, loop through that to find which one you need, and then set the disabled attribute as I showed above.
这篇关于如何通过功能禁用jQuery对话框中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!