如何从函数中禁用 jQuery 对话框中的按钮? [英] How can I disable a button in a jQuery dialog from a function?

查看:21
本文介绍了如何从函数中禁用 jQuery 对话框中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 Dialog 有一行可以使用(在按钮"部分下.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆