我有一个与一些链接链接的图像滑块,在桌面版本中,当您单击图像时,它会正确地指向链接,但当我切换到移动版本并单击链接不起作用的图像时,我尝试使用以下Jquery解决此问题:
jQuery (document) .ready (function () {
jQuery ('. fullwidthbanner-container ul> li: nth-child (3) img'). each (function () {
var currentImage = jQuery (this);
currentImage.wrap ("<a target='_self' href='http://jquerybyexample.blogspot.com'" + currentImage.attr("href") + "'</a>");
});
});但是它仍然不起作用,有没有办法让我把这些图片链接起来?
发布于 2020-04-28 10:41:40
建议尝试下面这样的方法。
jQuery(function($) {
$('.fullwidthbanner-container > ul > li:eq(3) > img').each(function(i, el) {
$(el).wrap(function() {
return "<a href='http://jquerybyexample.blogspot.com" + $(this).attr("src") + "'></a>";
});
});
});更多信息请访问:https://api.jquery.com/wrap/
图像通常具有src属性,而不是href。
https://stackoverflow.com/questions/61471462
复制相似问题