2 回答

TA贡献1880条经验 获得超4个赞
就像我说我不使用 jQuery 但我认为基本上你的代码发生的事情是事件侦听器需要引用接收click事件的元素然后找到子节点〜img.imageresource
顺便我忘了说,标签应该是img而不是image
$(function() {
$('.pop').on('click', function() {
/* or should that be $( this ) ?? */
let child=this.querySelector('img.imageresource')
$('.imagepreview').attr( 'src', child.src );
$('#imagemodal').modal('show');
});
});

TA贡献1895条经验 获得超3个赞
如果您正在寻找基于纯jquery的解决方案,那么您可以使用以下代码
$('.pop').on('click', function() {
var imgSrc = $(this).children('.imageresource').attr('src'); //get image src here
$('.imagepreview').attr('src', imgSrc );
$('#imagemodal').modal('show');
});
添加回答
举报