當表示自舉模式中,可以使用代碼如很容易地檢索相關(guān)聯(lián)的數(shù)據(jù)$('#myModal').on('show.bs.modal', function (e) { var id = $(e.relatedTarget).data('id'); alert(id);}關(guān)閉引導(dǎo)程序模式時是否可能相同?特別是當被特定按鈕(即確認按鈕,而不是兩個取消按鈕)關(guān)閉時?在relatedTarget似乎沒有提供任何button的模式里面,也不在Shidden.bs.modal事件。在下面的操場data-id屬性值中,當modal以類似方式data-id顯示模式主體時,單擊“是”時,應(yīng)在刪除按鈕下方顯示刪除值:$(document).ready(function () { $('#deleteModal').on('show.bs.modal', function (e) { $('#testOutput,#testOutput2').text(''); var id = $(e.relatedTarget).data('id'); $('#deleteId').text(id || 'id retrieval failed'); }); $('#deleteModal').on('hidden.bs.modal', function (e) { var id = $(e.relatedTarget).data('id'); //does not work $('#testOutput2').text(id || '"hidden.bs.modal" id retrieval failed'); }); $('#confirmDeleteBtn').click(function (e) { var id = $(e.relatedTarget).data('id'); //does not work //var id = $(this).closest('.modal').data('id'); //doesnt work neither $('#testOutput').text(id || '"btn.close .modal" id retrieval failed'); });});<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script><div class="col offset-3"> <div class="d-flex"> <button class="mt-4 btn btn-primary" data-toggle="modal" data-target="#deleteModal" data-id="42">delete record 1</button> <button class="mt-4 btn btn-primary" data-toggle="modal" data-target="#deleteModal" data-id="123">delete record 2</button> </div> <h5 class="mt-4 text-danger" id="testOutput"></h5> <h5 class="text-danger" id="testOutput2"></h5></div>請注意id,打開的button時間不是恒定的,即有許多deletebutton可以打開單個對話框。
關(guān)閉時獲取Bootstrap的模態(tài)初始數(shù)據(jù)-*
慕哥6287543
2021-04-02 13:15:14