我不知道如何将 src img 转移到另一个带有图片的块中,src 显示在控制台中。并且 [Object Object] 被插入到 src
<!DOCTYPE html> <html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title> </head> <body>
<div class="img-wr">
<img src="a.png" alt="">
<a class="st" href="javascript:void(0);">получить</a class="st">
</div>
<div class="img-wr">
<img src="b.png" alt="">
<a class="st" href="javascript:void(0);">получить</a>
</div>
<div class="img-wr">
<img src="3.jpeg" alt="">
<a class="st" href="javascript:void(0);">получить</a>
</div>
<div class="img-wr">
<img src="4.jpg" alt="">
<a class="st" href = "javascript:void(0);">получить</a>
</div>
<div class="sn">
<img class="re" src="" alt="">
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<!-- <script src="sc.js"></script> -->
<!-- <script src="script.js"></script> -->
<script src="sm.js"></script> </body> </html>
$( document ).ready(function() {
$('.st').click(function () {
let imgr = $(this).closest('.img-wr').find('img').attr('src');
$('.re').attr('src', $(imgr));
});
});
因此,您自己将其包装在一个对象
$(img)
中,将其删除$()
并传递它img
: