删除div后显示弹出窗口

时间:2017-05-19 09:52:58

标签: javascript jquery

我想首先删除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;
&#13;
&#13; enter image description here

@quirimmo请看:

2 个答案:

答案 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:

https://jsfiddle.net/91x9ta3n/12/

答案 1 :(得分:1)

使用超时,因此警报和删除不会同时执行。

mvc

jsfiddle:https://jsfiddle.net/91x9ta3n/7/

相关问题