Hy! 我从数据库中调用图像的div。通过点击任何图像,我显示具有产品详细信息的相同模态。如何动态点击图片ID
为了显示模态,在JavaScript中,我通过src接收图像,这被点击并因此打开相同的模态。 现在我想要获取每个图像的id在php脚本中使用该id的点击。 我该怎么做?
PHP
<div data-toggle='modal' data-target='#myModal'>
<h3 align='center'>$product_name</h3>
<center>
<img src='admin_area/product_images/u_buyer_product_img/$product_image1' class='getSrc' />
<br></center>
</div>
的JavaScript
<script>
$(document).ready(function(){
$('.getSrc').click(function() {
var src =$(this).attr('src');
$('.showPic').attr('src') = src;
});
});
</script>
HTML
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<img src="" class="showPic">
<div class="modal-header" style="padding:35px 50px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 align="left">Product Name
</h3>
<p>Product Discription</p>
</div>
<div class="modal-body" style="padding:40px 50px;">
<div>
<label> Product-Code :- </label>
</div>
<div>
<label> Quantity :- </label>
</div>
<div>
<label> Price :- </label>
</div>
<div>
<label> Action :- </label>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger btn-default pull-left" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
</div>
</div>
</div>
</div>
只需使用'this.id' – Rayon
'$(本).attr( '身份证');'? – guradio
我无法在html中看到任何id属性? –