Javascript 如何在modal中传递数据属性
我需要在模式中传递数据属性。单击链接时,在src中附加图像标记。下面是我的代码。我很困惑。我知道我们可以使用JavaScript onclick方法通过引用进行传递。还有人能给我可执行代码。我的代码如下。我并不擅长制作JavaScript函数Javascript 如何在modal中传递数据属性,javascript,html,bootstrap-modal,Javascript,Html,Bootstrap Modal,我需要在模式中传递数据属性。单击链接时,在src中附加图像标记。下面是我的代码。我很困惑。我知道我们可以使用JavaScript onclick方法通过引用进行传递。还有人能给我可执行代码。我的代码如下。我并不擅长制作JavaScript函数 &时代; 查看图像 费用提交 接近 您可以使用引导模式侦听器show或show并将数据属性值传递给 &时代; 查看图像 费用提交 接近 如果要将映像包含到引导模式中,请尝试以下操作 $('#checkImage').on('show.bs.modal
&时代;
查看图像
费用提交
接近
您可以使用引导模式侦听器show
或show
并将数据属性值传递给
&时代;
查看图像
费用提交
接近
如果要将映像包含到引导模式中,请尝试以下操作
$('#checkImage').on('show.bs.modal', function (e) {
var img = $(e.relatedTarget).data('myimage');
//alert(img);
$("#thanks").attr("src",img);
});
检查这个官方演示
<a id = 'checkImage' >Image</a>
<div id = 'imagemodal' class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">View Image</h4>
</div>
<div class="modal-body">
<h1>Fee Submit</h1>
<img src="http://www.userlogos.org/files/logos/Karmody/alaTest_Iphone01a.png" id="imagepreview" >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$(function() {
$('#checkImage').on('click', function() {
$('.imagepreview').attr('src', $(this).find('img').attr('src'));
$('#imagemodal').modal('show');
});
});