javascript - 使用 jquery 根据替代文本向某些图像添加类?

标签 javascript jquery

我如何使用 jquery 根据替代文本向某些图像添加类?

这里是图片的例子:

<img border="0" src="images/Product/icon/26086_1_.jpg" 
alt="Show Picture 1" onclick="setcolorpicidx_26086(1);" 
style="cursor:hand;cursor:pointer;">

因此,如果替代文本包含“显示图片”,则添加一类 image-nav

最佳答案

你也可以使用过滤器:

$('img').filter(function() {
    return $(this).prop('alt').indexOf('Show Picture')!=-1;
}).addClass('image-nav');

关于javascript - 使用 jquery 根据替代文本向某些图像添加类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11760310/

相关文章:

jquery - 循环遍历每个表行内的每个输入

javascript - jquery加载定义变量

javascript - 将 onclick 添加到 CSS 类

javascript - jQuery 调整大小功能出现问题

javascript - React 动态导入 Svg 文件

javascript - 将 Iframe 中的 Fancybox 居中到父中心

javascript - 如果 jQuery 中的文本是阿拉伯语,则将类添加到文本的父级

javascript - 仅在元素上触发 'click' 事件,而不考虑其填充

javascript - JQuery show() 方法没有按预期工作

javascript - Vis.js 时间线动态变化