2017-09-25 97 views
0

這是我編輯按鈕的HTML代碼。當我點擊編輯按鈕時,沒有模式彈出。莫代爾沒有顯示只有背景出現

<div class="modal fade" id="editModal"> 
    <div class="modal-dialog" role="document"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <h5 class="modal-title">Edit record</h5> 
       <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
        <span aria-hidden="true">&times;</span> 
       </button> 
      </div> 
      <div class="modal-body"> 
       <div class="form-group"> 
        <input type="hidden" id="editid" name="id" class="form-control"> 
        <input type="text" id="editname" name="name" class="form-control"> 
       </div> 
      </div> 
      <div class="modal-footer"> 
       <button type="submit" onclick="editModal(event)" class="btn btn-primary">Save changes</button> 
       <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> 
      </div> 
     </div> 
    </div> 
</div> 

當您單擊保存更改時,下面是第二個模式的代碼。

<div class="modal fade" id="confirmationModal1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
     <form action="php/edit_client.php" method="post"> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <h4 class="modal-title">Confirmation</h4> 
       </div> 
       <div class="modal-body"> 
        Are you sure you want to edit this client? 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> 
        <button type="submit" class="btn btn-primary" onclick="validateForm()">Save</button> 
       </div> 
      </div> 
     </form> 
    </div> 
</div> 

這是要顯示的模式的JavaScript。

function validateForm(e) { 

    } 

    function editModal(event) { 
    $("#editModal").modal("show"); 

    focusedid = e; 
    identifier = focusedid.split('-')[1]; 

    $("#editid").val($("#id-" + identifier).val()); 
    $("#editname").val($("#name-" + identifier).val()); 
} 
+0

您使用引導? – imcvampire

+0

嘗試創建片段或共享提琴手。 –

+0

您忘記在代碼片段中添加編輯按鈕,您也在'editModal'函數上啓動'editModal',這應該是confirmationModal嗎?因爲目前您在保存更改時在'editModal'內啓動'editModdal'。 – azs06

回答

0

也看到你的代碼,也許它是你的瀏覽器版本或之前其他正在運行的jQuery,我也有類似的問題,另一個項目的工作如下:

$('#editModal').on('show.bs.modal', function (event) { //here goes the modal id 
    var button = $(event.relatedTarget) // Button that activated the modal 
} var modal = $(this) 
    $('.alert').hide(); 
}) 

但在不同的版本,還是讓我覺得,我的修改代碼以下列之一:

$("#btn_show_modal").click(function(){ //here goes the button id that activates it 
    $("#editModal").modal("show"); //here goes the modal id 
}); 

但在此之前,該按鈕把下面的代碼:

<a data-toggle="modal" data-target="#editModal"> //where is the link to modal, and data-targat indicates to which modal id references. practicamente, la etiquieta a indica el vinculo a el modal, incluso puedes colocar ese viculo a el boton para ahorrar codigo. 
    <button type="button" value="Modal"/> //default button 
</a> 

最好如果你說西班牙語翻譯,直到意見了解它。祝你好運。

//De preferencia si hablas español traduce hasta los comentarios para entenderlo. Buena suerte.