找到图像src:包含?
大家早,
我有一个像这样的图像列表:
使用jQuery如何在ul#preload中查找包含特定字符串的所有图像src,例如“green”
就像是…
var new_src = jQuery('#preload img').attr('src')*** that contains green ***;
你需要使用*=
选择器 :
jQuery('#preload img[src*="green"]')
如果您希望它不区分大小写,那将会更加困难:
var keyword = "green"; $("#preload img").filter(function(keyword) { return $(this).attr("src").toLowerCase().indexOf(keyword.toLowerCase()) != -1; });
您可以使用属性包含选择器 ( [attr*=value]
),如下所示:
jQuery('#preload img[src*=green]')