2016-05-15 33 views
1

這個問題有點長,所以很明顯,在此先感謝!通過使用JS和PHP的錨標籤傳遞值

簡介:

我現在有一個引導莫代爾其中包含一個。該模式是從錨標籤啓動的。

但是,的鏈接取決於PHP變量$id,它是從MySQL查詢時動態的。


問:

如何傳遞的$id在引導模態的,該值通過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> 
    
  • 定位標記(要啓動模式)

    <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,該應該去:

https://example.com/page/?id=26 // id needs to be 26 as $id is 26 
+0

有作爲'<一類= 「按鈕」' – mplungjan

+0

@mplungjan哦,注意沒有這樣的事,感謝 – Panda

+0

爲什麼不'的「target =」iframeName「'?或只是'