我希望点击按钮后,能够获取特定的图片地址,并在
img-block
区块中显示该图片。
HTML<button class="button">Click</button>
<div class="img1">
<img src="img.jpg" alt="">
</div>
<div class="img-block"></div>
CSS
=>CSS
.img-block{
position: absolute;
top:10%;
right:10%;
background-color: red;
width: 500px;
height: 500px;
}
.img1 img{
width: 200px;
}
JS
$('.button').click(function(){
var images = $('.img1 img').attr(src);
alert(images);
});
但是现在我面临的问题是获取img src。
因此我使用alert进行测试,结果是没有弹出任何内容。