如何禁用jQuery UI对话框上的按钮? [英] How can I disable a button on a jQuery UI dialog?

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

问题描述

如何在jQuery UI对话框上禁用按钮 .我似乎在上面的链接的任何文档中都找不到.

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.

我在模式确认中有2个按钮(确认"和取消").在某些情况下,我想禁用确认"按钮.

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

推荐答案

如果包含 .button() jQuery UI所包含的plugin/widget (如果您拥有完整的库并且在1.8+上,则具有它),则可以使用它来禁用按钮 并以可视方式更新状态,像这样:

If you're including the .button() plugin/widget that jQuery UI contains (if you have the full library and are on 1.8+, you have it), you can use it to disable the button and update the state visually, like this:

$(".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,请执行以下操作:


If you want it inside a specific dialog, say by ID, then do this:

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

在其他情况下,其中 :contains() 可能会给出误报,那么您可以使用 .filter() 像这样,但是由于您知道您的两个按钮,因此在这里过大了. 如果在其他情况下是这种情况,则看起来像这样:

In other cases where :contains() might give false positives then you can use .filter() like this, but it's overkill here since you know your two buttons. If that is the case in other situations, it'd look like this:

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

这将防止:contains()与其他内容的子字符串匹配.

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

这篇关于如何禁用jQuery UI对话框上的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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