gpt4 book ai didi

jquery - Bootstrap 模态。使用 Jquery 动态包含图像

转载 作者:行者123 更新时间:2023-12-01 00:06:00 36 4
gpt4 key购买 nike

我想打开一个模态来显示用户单击的图像。所以,我有很多带有 .image

类的图像
<a href="#">
<img data-toggle="modal" data-target="#modal_image" src="..." class="image thumbnail img-responsive">
</a>

我有一个模式:

<div class="modal fade" id="modal_image" tabindex="-1" role="dialog" aria-labelledby="modal_imagen" aria-hidden="true">
<div class="modal-body">
<img class = "image_modal" src="">
</div>
</div>

还遵循用于定义模态图像的 JQuery 代码:

$('.image').click(function(){
var new_src = $(this).attr('src');
$('#image_modal').attr('src', new_src);
});

但是它不起作用。希望这不是一个愚蠢的错误,非常感谢您的帮助。

最佳答案

您可以尝试这样的操作( Live Demo ):

$('#modal_image').on('show.bs.modal', function (e) {
var src = $(e.relatedTarget).attr('src');
$(this).find('.modal-body > img.image_modal').attr('src', src);
});

查看更多信息Bootstrap Website :

About show.bs.modal event:

This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the event.

关于jquery - Bootstrap 模态。使用 Jquery 动态包含图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25335744/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com