如何从ID为

时间:2016-05-04 02:10:52

标签: php modal-dialog href bootstrap-modal

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

<?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的链接来查看模态对话框。我没有找到与我相同的问题所以我决定寻求帮助。

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:-1)

您是否浏览过Bootstrap文档?这很容易。 RTM http://getbootstrap.com/javascript/#modals