javascript - JQuery 选择器 : How to get a img id that have an one and only one attribute

标签 javascript jquery html jquery-selectors

例如,如果页面上只有一个图像具有属性 aria-disabled = "true",如何使用 jquery 选择器来获取此元素?请注意,并非所有图像都具有 aria-disabled ,其中一些没有此属性,其中一些具有 aria-disabled = "false"。只有一个 图像具有 aria-disabled = "true"。谢谢

例如。

$(img :  aria-disabled = "true").attr(id);

当然这应该是无效的synatx

最佳答案

试试这个

$('img[aria-disabled="true"]').attr('id');

关于javascript - JQuery 选择器 : How to get a img id that have an one and only one attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14497417/

相关文章:

javascript - Javascript 中是否有等效的 Java 集合?

javascript - Safari 12.1 中的变换原点动画问题

html - 为下拉菜单导航栏 Bootstrap 定义样式

javascript - 如何使用 javascript 为谷歌分析创建点击事件

javascript - 在Javascript中获取数字之间的数字步骤

javascript - 动态创建<td>相关函数问题

asp.net-mvc-3 - 通过 Ajax 在 ASP.NET MVC3 中上传文件不起作用

php - 遍历javascript中的表单元素并添加获取的值

javascript - jQuery 的 offset() 在 "elem.getClientRects is not a function"处崩溃

jquery - 创建叠加层以发送消息