所以基本上我想做的是抓取页面中图像的链接,并将它们转换为图像。现在,我的代码将抓取论坛上的帖子中的任何链接,并将它们转换为图像,但我希望它更具体。我希望能够使用主要的4个网络图像扩展(.jpg,.gif,.png,.bmp)来抓取图像。我是jQuery的新手,所以我真的很想在这方面得到一些帮助。以下是我到目前为止的代码:
(function($) {
if ($('#nav a[href*="/forum/3828932/"]').length && location.href.indexOf('/1/') !== -1) {
$('td.c_post:eq(0) a').each(function () {
link = $(this).attr('href');
$(this).html('<a href="' + link + '"><img src="' + link + '" alt="Icon" /></a>')
});
}
})(jQuery);发布于 2011-10-26 14:43:41
您可以尝试使用ends-with选择器来选择具有这些值http://api.jquery.com/attribute-ends-with-selector/的href ends的锚点
和多个选择器http://api.jquery.com/multiple-selector/
因此,您的选择器可能如下所示
$('td.c_post:eq(0) a[href$=".jpg"],td.c_post:eq(0) a[href$=".png"],td.c_post:eq(0) a[href$=".gif"],td.c_post:eq(0) a[href$=".bmp"]')https://stackoverflow.com/questions/7899351
复制相似问题