我有一个图像列表,当我单击其中一个图像时,我想更改 div 的背景。我有这样的东西,但它不起作用:
jQuery:
$('.container-inner').find('img').click(function(){
var $url = $(this).attr('src');
console.log($url);
$('.container-outer').css({'background-image': $url});
});
的HTML:
<div class="container-outer">
<div class="container-inner">
<a href="#"><img src="http://d1c739w2xm33i4.cloudfront.net/2.2/top_image.jpg"></a>
<a href="#"><img src="http://a.tgcdn.net/images/products/additional/large/e718_broke_something.jpg"/></a>
<a href="#"><img src="http://d1c739w2xm33i4.cloudfront.net/2.2/top_image.jpg"></a>
<a href="#"><img src="http://inspiretrends.com/wp-content/uploads/2013/07/InteractiveSVG.jpg"/></a>
<a href="#"><img src="http://images5.fanpop.com/image/photos/30800000/-Random-random-30843841-1920-1080.jpg"/></a>
<a href="#"><img src="http://inspiretrends.com/wp-content/uploads/2013/07/InteractiveSVG.jpg"/></a>
<a href="#"><img src="http://inspiretrends.com/wp-content/uploads/2013/07/InteractiveSVG.jpg"/></a>
</div>
</div>
有任何想法吗?