[英]Passing a link to bootstrap modal window with a iframe
I have a table where each row has a link to edit the data for that record. 我有一个表,其中每一行都有一个链接来编辑该记录的数据。 The link will be in the following format -> modal_edit.php?id=2
链接将采用以下格式-> modal_edit.php?id = 2
On clicking the link it should open the link in an iframe which is located inside a bootstrap-4 modal window. 点击链接后,它应该在bootstrap-4模态窗口内的iframe中打开链接。
I am not sure how to achieve this. 我不确定如何实现这一目标。 I have tried searching for a solution but those did not help.
我曾尝试寻找解决方案,但这些并没有帮助。
Here is my code for the link: 这是我的链接代码:
<td><center><a href="modal_edit.php?id=' . $row['id'] . '" data-toggle="modal" data-target="#myModal"><i class="fas fa-edit"></i></a></center></td>
And code for modal: 和模态代码:
<div class="modal fade" id="myModal">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<iframe src="modal_edit.php" width="600" height="380" frameborder="0" allowtransparency="true"></iframe>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
I have also tried sending the link using data-id and updating the src but it didn't seem to work. 我也尝试过使用data-id发送链接并更新src,但似乎没有用。 I am fairly new to coding and any help in this regard will be appreciated.
我是编码的新手,在这方面的任何帮助将不胜感激。
<td>
<center><a href="#" data-href="modal_edit.php?id=' . $row['id'] . '" class="showModal"><i class="fas fa-edit"></i></a></center>
</td>
$(document).ready(function() {
$(".showModal").click(function(e) {
e.preventDefault();
var url = $(this).attr("data-href");
$("#myModal iframe").attr("src", url);
$("#myModal").modal("show");
});
});
You can use set the src of an iframe on click of the a tag. 您可以通过点击标签来设置iframe的src。 Get the value from
data-href
, set the src of an iframe and then show the modal window. 从
data-href
获取值,设置iframe的src,然后显示模式窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.