【问题标题】:How to modal in PHP with delete confirmation如何在 PHP 中使用删除确认进行模态
【发布时间】:2016-06-09 03:52:03
【问题描述】:

我正在尝试在我的系统中添加一个模式,当您单击它时,会出现一个模式并询问您是否要删除该特定数据。

但在我目前的代码中,当您单击按钮时,它会将您定向到没有模式的空白页面。 id 正确传递,但如何输出模态?

这是我的 PHP 代码:

        <?php

        while(mysqli_stmt_fetch($stmt)) {
        echo "<tr>";
        echo "<td class=\"col-md-2\" onclick=\"document.location = 'modal_delete.php?id=$id';\"><button type=\"button\" class=\"btn btn-primary btn-md\" data-toggle=\"modal\" data-target=\"#myModal\">Delete</button></td>";
        echo '</tr>';
      }

      ?>

这里是模态的代码(modal_delete.php):

<?php

include '../session.php';
include 'header.php';

?>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Delete</button>
      </div>
    </div>
  </div>
</div>

我希望你们帮助我。谢谢

【问题讨论】:

    标签: javascript php jquery twitter-bootstrap


    【解决方案1】:

    modal_delete.php 上,您需要在 DOM 准备好后使用 javascript 触发模式。

    <script>
      $(function () {
       $('#myModal').modal('show');
     });
    </script>
    

    【讨论】:

    • 我将在我的modal_delete.php?中添加此代码
    • 我建议阅读一下 php、html 和 javascript 的作用以及它们如何组合在一起。做事不理解是没有用的。
    • 过去几天我实际上在阅读 javascript。我对 php 和 html 有很好的了解。谢谢
    猜你喜欢
    • 2020-07-07
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 2014-05-03
    相关资源
    最近更新 更多