我如何使用 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/