我想根据条件禁用对话框中出现的按钮。问题是我如何访问该按钮,因为它是通过对话框动态生成的?
在对话框中生成的 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>
最佳答案
我假设您的代码中有一个拼写错误,并且您无意关闭开始跨度标记,因此您的代码是
<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);
关于jquery - 如何通过匹配范围内的文本来选择按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4722399/