2013-06-05 38 views
1

我遇到問題。我有一些PHP腳本,在我的數據庫中創建帖子列表。將Anchor從Anchor放置到Modal Bootstrap

這是基於數據庫

一些ID代碼

<td><?php echo "$r[date_create]"; ?></td> 
<td><?php echo "$r[date_update]"; ?></td> 
<td><?php echo "$r[hitcount]"; ?></td> 
<td> 
<a href="edit.php?id=<?php echo "$r[id]"; ?>"><i class="icon-pencil"></i></a> 
<a href="#myModal" role="button" data-toggle="modal" id="<?php $r[id]; ?>"> 
<i class="icon-remove"></i></a> 
</td> 

這種語法呼叫被叫MyModal

,你可以看到,錨(

<a href="#myModal" 

)獲取模式

但我不能通過從PHP腳本生成的值傳遞給我的模態窗口

這裏的模態窗口語法

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
        <h3 id="myModalLabel">Delete Confirmation</h3> 
       </div> 
       <div class="modal-body"> 
        <p class="error-text">Are you sure you want to delete the post?</p> 
       </div> 
       <div class="modal-footer"> 
        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> 
        <a class="btn btn-danger" data-dismiss="modal" href="delete.php?id=THE ID SHOULD BE HERE ">Delete</a> 
       </div> 
      </div> 

我想從錨點的ID以上發生在delete.php?ID = ID應該在這裏

如何做到這一點?

預先感謝您

回答

1

您必須手動打開模式對話框,而不是依賴於數據的屬性來完成這項工作。僞代碼可能是這樣的:

$(function() { 
    // Attach a click handler to your link 
    $('#modal_opener').click(function() { 
    // Open the modal box 
    $('#myModal').modal('show'); 
    // Set the id to the hidden field 
    $('#id_on_your_modal').val("<?php print $r[id] ?>"); 
    }); 
}); 

記住javascript代碼必須在你的HTML代碼相同的頁面,這樣你就可以訪問你的PHP變量。