1
我有一個名爲childDiv
的div,它住在parentDiv
內。jQuery模態追加div,然後前置到前面的div
<div id="parentDiv">
<p>Parent should be on top</p>
<div id="childDiv">
<p>Child</p>
</div>
</div>
當用戶點擊一個按鈕,我想childDiv
附加到模態對話框窗口。但是,一旦用戶關閉模式,我想childDiv
回到parentDiv
。
$(document).ready(function() {
$("#myBtn").click(function() {
$("#myModal").modal('show');
$("#childDiv") .appendTo(".modal-body");
});
$('#myModal').on('hide.bs.modal', function (e) {
$("#childDiv") .prependTo("parentDiv");
})
});
請看下面的小提琴。我會感謝您的幫助!