gpt4 book ai didi

javascript - 使用 JS 和 PHP 通过 anchor 标记传递值

转载 作者:行者123 更新时间:2023-11-30 11:58:31 26 4
gpt4 key购买 nike

这个问题有点长,这样就清楚了,先谢谢了!

简介:

我目前有一个包含 <iframe> 的 Bootstrap Modal .模式是从 anchor 标记启动的。

但是,<iframe> 的链接取决于一个 PHP 变量,$id这是动态的,因为它是从 MySQL 查询的。


问题:

如何传递 $id 的值?到 <iframe>在 Bootstrap 模态中,通过 data-value或者还有其他方法吗?


代码:

  • 引导模式

    <!-- Modal content-->
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</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>
  • anchor 标记(启动模式)

    <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>

所以,如果 $id26 , <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> 

关于javascript - 使用 JS 和 PHP 通过 anchor 标记传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37237745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com