Javascript 使用JS和PHP通过锚定标记传递值
这个问题有点长,所以很清楚,提前谢谢 导言: 我目前有一个引导模式,其中包含一个Javascript 使用JS和PHP通过锚定标记传递值,javascript,php,jquery,Javascript,Php,Jquery,这个问题有点长,所以很清楚,提前谢谢 导言: 我目前有一个引导模式,其中包含一个。模态从锚定标记启动 但是,的链接取决于一个PHP变量,$id,该变量在从MySQL查询时是动态的 问题: 如何在引导模式下通过数据值将$id的值传递给,或者是否有其他方法 代码: 引导模式 <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button
。模态从锚定标记启动
但是,
的链接取决于一个PHP变量,$id
,该变量在从MySQL查询时是动态的
问题: 如何在引导模式下通过
数据值
将$id
的值传递给
,或者是否有其他方法
代码:
- 引导模式
<!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h2 class="modal-title">Edit Status</h2> </div> <div class="modal-body"> <iframe src="https://example.com/page/?id="></iframe> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div>
阐述:
$id
需要通过
标记传递:
<a type="button" data-toggle="modal" data-id="<?php $print id; ?>" data-target="#myModal">Open Modal</a>
手动更改iframe的
src
怎么样
<a type="button" data-toggle="modal" data-id="<?php $print id; ?>" data-target="#myModal"
onclick="
document.getElementById('iframe-id').src = $(this).data('id');
"
>Open Modal</a>
为什么不呢
<a href="https://example.com/page/?id=<?php $print id; ?>" target="iframeName"
没有像@mplungjan这样的东西哦注意到了,谢谢为什么没有@mplungjan非常感谢,我试过了,它成功了:)你想把它写成一个答案吗?试试open,在javascript函数openpopup(id){//user your id here document.getElementById('id_of_modal_popup')。modal('show')}谢谢你的答案:)
https://example.com/page/?id=26 // id needs to be 26 as $id is 26
<a type="button" data-toggle="modal" data-id="<?php $print id; ?>" data-target="#myModal"
onclick="
document.getElementById('iframe-id').src = $(this).data('id');
"
>Open Modal</a>
<a href="https://example.com/page/?id=<?php $print id; ?>" target="iframeName"
<iframe src="https://example.com/page/?id=<?php $print id; ?>"></iframe>