2014-04-11 26 views
0

我使用的是建立一個表中的PHP ...從dynamicallly創建的按鈕打開引導模式?

echo '<td><button type="button" class="btn btn-default btn-xs" id="edit_'. $info['tablename'] .'">Edit</button></td>'; 

我在我的HTML這個#editModal模式直接從引導解除...

<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true"> 
    //Modal content from Bootstrap example. 
</div> 

當我點擊「Edit 「按鈕,沒有任何反應。沒有控制檯錯誤,沒有。我遺漏的delet命令工作得很好,但它不涉及模態。這裏是我試圖使用的jQuery ...

$(document).on('click',".table .btn",function (e) { 
    e.preventDefault(); 
    var array = String($(this).attr('id')).split('_'); 
    var id = array[1]; 
    //Get the command off the button id. 
    var command = array[0]; 

    if (command == "delete"){ 
     //do delete stuff 
    } 
    if (command == "edit"){ 
     // I want to show this modal but it doesn't work. 
     $('#editModal').modal({ 
      "show":"true" 
     }); 
    } 
}); 

回答

0

我認爲你只需要以下內容。

if (command == "edit"){ 
    // I want to show this modal but it doesn't work. 
    $('#editModal').modal("show"); 
}