找到包含的图像src? [英] find image src that :contains?
本文介绍了找到包含的图像src?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好,
我有一个这样的图像列表:
I have a list of images like so:
<ul id="preload" style="display:none;">
<li><img src="afx4000z-navy-icon-1_thumb.jpg"/></li>
<li><img src="afx4000z-green-icon-1_thumb.jpg"/></li>
</ul>
使用jQuery如何在ul#preload中查找包含特定字符串(例如绿色")的所有图像src.
Using jQuery how find all image src's within ul#preload that contain a specific string eg."green"
类似...
var new_src = jQuery('#preload img').attr('src')*** that contains green ***;
推荐答案
您需要使用 *=
选择器:
You need to use the *=
selector:
jQuery('#preload img[src*="green"]')
如果您希望它不区分大小写,那么会有点困难:
If you want it to be case insensitive, it will be a bit more difficult:
var keyword = "green";
$("#preload img").filter(function(keyword) {
return $(this).attr("src").toLowerCase().indexOf(keyword.toLowerCase()) != -1;
});
这篇关于找到包含的图像src?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文