[英]Passing value through anchor tag using JS and PHP
这个问题有点长,所以很明显,提前谢谢!
我目前有一个包含<iframe>
的Bootstrap Modal。 模态是从锚标签启动的。
但是, <iframe>
的链接取决于PHP变量, $id
是动态的,因为它是从MySQL查询的。
我怎样才能的值传递$id
到<iframe>
在自举模态,通过data-value
或者是还有什么别的办法吗?
Bootstrap模态
<!-- 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>
锚标记 (启动模态)
<a type="button" data-toggle="modal" data-id="<?php $print id; ?>" data-target="#myModal">Open Modal</a>
PHP代码 (设置变量, $id
)
<?php while ($row = mysqli_fetch_row($result1)){ list($id, $content) = $row; ?> <tr> <td> <p> <a type="button" data-toggle="modal" data-id="<?php $print id; ?>" data-target="#myModal">Open Modal</a> </p> <?php } ?> </td> </tr> </table>
$id
需要通过<a>
标签传递:
<a type="button" data-toggle="modal" data-id="<?php $print id; ?>" data-target="#myModal">Open Modal</a>
因此,如果$id
为26
, <iframe>
应该转到:
https://example.com/page/?id=26 // id needs to be 26 as $id is 26
为什么不
<a href="https://example.com/page/?id=<?php $print id; ?>" target="iframeName"
? 要不就
<iframe src="https://example.com/page/?id=<?php $print id; ?>"></iframe>
如何手动更改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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.