【发布时间】:2021-10-26 19:58:18
【问题描述】:
如何在每次点击 #thumbs1 时将 #largeImage1 SRC 属性添加到跨度背景图像中?它应该使用新的 SRC 更新 span 背景图像。
我似乎无法让它工作。我的语法不起作用。你能帮忙吗?
<a href="#img1">
<img id="largeImage1" src="google-1.png" />
</a>
<a href="#" class="lightbox" id="img1">
<span></span>
</a>
<div id="thumbs1">
<img src="google-1.png" />
<img src="google-2.png" />
<img src="google-3.png" />
<img src="google-4.png" />
</div>
$('#thumbs1').delegate('img', 'click', function() { <-- This is working fine
$('#largeImage1').attr('src', $(this).attr('src').replace('thumb', 'large')); <-- This is working fine
$('span').css('background-image', 'url()'); <---- This is the problem, I can see in the inspection tool, that when clicked it adds background-image to span but doesn't add image SRC inside it. I don't know what to call inside the url. I checked online but seemed confusing
});
提前谢谢你
【问题讨论】:
-
我没有在任何图像的 SRC 中看到文本
"thumb"。url()部分还应该包含哪个 URL? -
谢谢,我正在尝试在 'span' 'background-image' 中添加 'largeImage1' SRC。谢谢
标签: html jquery css image lightbox