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');
});
添加回答
舉報
