引导模式。使用Jquery动态包含图像
我想打开一个引导模式。使用Jquery动态包含图像,jquery,twitter-bootstrap,modal-dialog,Jquery,Twitter Bootstrap,Modal Dialog,我想打开一个模式,显示用户单击的图像。因此,我有许多类的图像 <a href="#"> <img data-toggle="modal" data-target="#modal_image" src="..." class="image thumbnail img-responsive"> </a> 下面的JQuery代码应该定义模态的图像: $('.image').click(function(){ var new_src = $(this
模式
,显示用户单击的图像。因此,我有许多类的图像
<a href="#">
<img data-toggle="modal" data-target="#modal_image" src="..." class="image thumbnail img-responsive">
</a>
下面的JQuery
代码应该定义模态的图像:
$('.image').click(function(){
var new_src = $(this).attr('src');
$('#image_modal').attr('src', new_src);
});
但它不起作用。希望这不是一个愚蠢的错误,非常感谢您的帮助。您可以尝试以下方法():
更多信息请查看:
关于show.bs.modal事件:
调用show instance方法时,此事件立即激发。
如果是由单击引起的,则单击的元素可用作
事件的相关目标属性
$('.image').click(function(){
var new_src = $(this).attr('src');
$('#image_modal').attr('src', new_src);
});
$('#modal_image').on('show.bs.modal', function (e) {
var src = $(e.relatedTarget).attr('src');
$(this).find('.modal-body > img.image_modal').attr('src', src);
});