Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何通过匹配范围内的文本来选择按钮_Jquery_Jquery Ui_Jquery Selectors - Fatal编程技术网

Jquery 如何通过匹配范围内的文本来选择按钮

Jquery 如何通过匹配范围内的文本来选择按钮,jquery,jquery-ui,jquery-selectors,Jquery,Jquery Ui,Jquery Selectors,我想根据条件禁用对话框中出现的按钮。问题是如何访问按钮,因为它是通过对话框动态生成的 在对话框中生成的html代码: <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="true"> <span> class="ui-button-text">Save&

我想根据条件禁用对话框中出现的按钮。问题是如何访问按钮,因为它是通过对话框动态生成的

在对话框中生成的html代码:

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="true">
    <span> class="ui-button-text">Save</span>
</button>

class=“ui按钮文本”>保存

您可以使用JQuery匹配以下属性:

$('button[role=button]').attr("disabled", true);

我假设您的代码中有一个输入错误,并且您并不想关闭开头的span标记,因此您的代码是

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="true">
    <span class="ui-button-text">Save</span>
</button>

要动态生成DOM,您可以使用
.live()

<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="true">
    <span class="ui-button-text">Save</span>
</button>
$("button span:contains('Save')").parent().attr("disabled", true);