具体实现: 改变img-box中img的src打的同时能够立刻同步到bgimg,以背景图的形式展现,"background-image":"url($('.img-box img').attr('src').substring(0,20))",这里的url要怎么写 <div class="bgimg"></div><div class="img-box"> <img src="img/2.jpg" alt=""></div>$(function(){ let h = document.documentElement.clientHeight; $(".bgimg").height(h) + "px"; $(".bgimg").css({"background-image":"url($('.img-box img').attr('src').substring(0,20))"}); console.log($('.img-box img').attr('src').substring(0,20)); })
1 回答
冉冉说
TA贡献1877条经验 获得超1个赞
$(".bgimg").css({'background-image':'url(' + $('.img-box img').attr('src').substring(0,20) + ')"'});
添加回答
举报
0/150
提交
取消