<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(function(){
$('.like').click(function(e){
e.preventDefault(); // prevent page reloading
alert( $('.post-container').find('#img').attr('src'));
});
</script>
<table id="posts">
<% result.forEach(function(item){ %>
<div class="post-container">
<%= item.img_id%>
<img src="<%= item.img_url %>" id="img" class="img">
<div><%= item.user_id%> </div>
<input type="button" name="like" id="like" value="Like" class="like">
</div>
<% }) %>
/ *执行ejs模板后看起来像* /
<div class="post-container">
1
<img src="https://www.w3schools.com/images/picture.jpg" id="img" class="img">
<div>UID001 </div>
<input type="button" name="like" id="1" value="Like" class="like">
</div>
<div class="post-container">
2
<img src="https://cdn.pixabay.com/photo/2014/06/03/19/38/board-361516_960_720.jpg"
id="img" class="img">
<div>UID001 </div>
<input type="button" name="like" id="2" value="Like" class="like">
</div>
[我想在下面单击按钮时提醒img src,当前在单击1或2个帖子时给出1个img src。