如何禁用 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 包含的插件/小部件(如果你有完整的库并且是 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.