我想首先删除div,然后显示我的弹出窗口。但在显示警报时,我能够看到div。 关闭弹出窗口后,div将被移除。
$("#btnRemoveDiv").on("click",function(){$("#divRemove").remove();
alert("Removed");});

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<div id="divRemove">Remove this div first then show the popup. Dont show this while the popup is opened!</div>
<input type="button" id="btnRemoveDiv" value="Remove">
&#13;
@quirimmo请看:
答案 0 :(得分:8)
使用when
将其作为承诺进行管理,它应该有效:
$("#btnRemoveDiv").on("click",function(){
$.when($('#divRemove').remove()).then(function() {alert('removed');});
});
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<div id="divRemove">Remove this div first then show the popup. Dont show this while the popup is opened!</div>
<input type="button" id="btnRemoveDiv" value="Remove">
JSfiddle:
答案 1 :(得分:1)