我遇到了这个片段,它的功能是用跨度包装 img 标签并制作跨度的图像背景图像。我的问题是,如何使它仅适用于某个 img 标签或某个 div 中的某些 img 标签?
$(文档).ready(函数(){
$("img").load(function() {
$(this).wrap(function(){
return '<span class="image-wrap ' + $(this).attr('class') + '"
style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
});
$(this).css("opacity","0");
});
});