How do I go about disabling a button on the jQuery UI dialog. I can't seem to find this in any of the documentation in the link above.

I have 2 buttons on the modal confirmation ("Confirm" and "Cancel"). In certain cases, I want to disable the "Confirm" button.

推荐答案

如果您包括jQuery UI包含的.button() plugin/widget个(如果您有完整的库,并且在1.8+上,您就有了它),您可以使用它来禁用按钮and,以可视化方式更新状态,如下所示:

$(".ui-dialog-buttonpane button:contains('Confirm')").button("disable");

You can give it a try here...or if you're on an older version or not using the button widget, you can disable it like this:

$(".ui-dialog-buttonpane button:contains('Confirm')").attr("disabled", true)
                                              .addClass("ui-state-disabled");

如果你想把它放在一个特定的对话框中,比如说按ID,那么就这样做:

$("#dialogID").next(".ui-dialog-buttonpane button:contains('Confirm')")
              .attr("disabled", true);

在其他:contains()可能给出假阳性的情况下,您可以像这样使用.filter(),但是这里的用法有点过头,因为您知道您的两个按钮.在其他情况下是这样的,它看起来是这样的:

$("#dialogID").next(".ui-dialog-buttonpane button").filter(function() {
  return $(this).text() == "Confirm";
}).attr("disabled", true);

This would prevent :contains() from matching a substring of something else.

Jquery相关问答推荐

Sheets从多张sheet中导入range匹配数据

jQuery:在mousemove事件期间检测按下的鼠标按钮

jQuery:如何动态检测窗口宽度?

ajax调用后Jquery事件不会触发

AngularJS 中的 ScrollTo 函数

如何滚动到AngularJS中的页面顶部?

jQuery Select 一个具有某个类的div,它没有另一个类

jQuery 中 prop() 和 attr() 的区别以及何时使用 attr() 和 prop()

使用 jQuery Select 焦点文本在 Safari 和 Chrome 中不起作用

jquery变量语法

JQuery Ajax Post 导致 500 内部服务器错误

为 jQuery AJAX 调用实现加载指示器

滚动 DIV 元素时如何防止页面滚动?

jQuery从字符串中删除'-'字符

父母的jQuery父母

如果一个元素正在被动画,我如何用 jQuery 找出?

使用 jQuery 在 Select 列表中隐藏选项

jquery $(window).width() 和 $(window).height() 在未调整视口大小时返回不同的值

获取对象属性中的最小值/最大值的快速方法

JQuery 判断 DOM 中的重复 id