2016-05-04 69 views
0

我有一个链接,当用户点击它,一个模式将显示包含以下内容:如何从ID链接打开模式?

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

回答

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

我并没有对如何获取该行价值的问题,我的问题是如何看待它与ID链接一个模态对话框。 – Felix