如何从带有id的链接打开模态框?

问题描述 投票:0回答:1

我有一个链接,当用户单击它时,将显示一个包含以下内容的模式:

<?php

    include ('dbcontroller.php');
    if(isset($_GET['view_id']))
    {
        $id=$_GET['view_id'];
        $sql = mysqli_query($conn, "SELECT * from press where id='$id'");
        $row = mysqli_fetch_array($sql);
    ?>  

    <input type="hidden" value="<?php echo  $row['id']; ?>" />
    <?php echo $row['reason']; ?>

        <a href="index.php" class="btn btn-primary">GO BACK</a>
    <?php 
    }
    $conn->close();
?>

上面的代码是我所做的,这样当用户单击链接时,它会将他重定向到该页面。但我希望它位于模式对话框中,因为它的内容不多。

这是用户点击的链接。我如何在模式对话框中打开此链接?

<a href="viewReason.php?view_id=<?php echo $row['id'];?>">Click to view </a>

我在这个网站和其他地方看到过一些,但它们只有一个没有 ID 的链接来查看模式对话框。我没有找到与我相同的问题,所以我决定寻求帮助。

php modal-dialog href bootstrap-modal
1个回答
0
投票

嘿,您可以使用以下代码来获取行值

 <!DOCTYPE html>
        <html lang="en">
        <head>

          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        </head>
        <body>

        <div class="container">

          <!-- Trigger the modal with a button -->

        <br><br><br><br>
        <table id="prab" border="1">
          <tr>
            <td>Jill</td>
            <td>Smith</td> 
            <td>50</td>
            <td><button type="submit" class="btn btn-default" data-toggle="modal" data-target="#myModal" value="Jackson"><span class="glyphicon glyphicon-envelope"></span>Invite</button></td>
          </tr>
          <tr>
            <td>Eve</td>
            <td>Jackson</td> 
            <td>50</td>
                <td><button type="submit" class="btn btn-default" data-toggle="modal" data-target="#myModal" value="smith" ><span class="glyphicon glyphicon-envelope"></span>Invite</button></td>
          </tr>
        </table>
          <!-- Modal -->
          <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">

              <!-- Modal content-->
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">Modal Header</h4>
                </div>
                <div class="modal-body">
                  <p>clicked value </p>

                  <input type="text" id="valueof" >


                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
              </div>


            </div>
          </div>

        </div>
         <script type="text/javascript">
            $('#prab').click(function(e){
                // alert($(e.target).val());
            document.getElementById("valueof").value = $(e.target).val(); 

        })
            </script>


        </body>
        </html>
© www.soinside.com 2019 - 2024. All rights reserved.