我试图弄清楚当从页面中删除元素时如何执行一些js代码:
jQuery('#some-element').remove(); // remove some element from the page
/* need to figure out how to independently detect the above happened */
Run Code Online (Sandbox Code Playgroud)
是否有为此量身定制的活动,例如:
jQuery('#some-element').onremoval( function() {
// do post-mortem stuff here
});
Run Code Online (Sandbox Code Playgroud)
谢谢.
是否有正式的方法来挂钩到jQuery.remove(),以便可以在之前/之后调用函数?
我有一个系统,其中某些处理程序附加到元素,有时这些元素被删除(例如,一个UI小部件,其主要元素被页面上的一些其他操作删除).如果可以通知处理程序他们的主要元素已被删除,我可以更轻松地运行清理例程.
我想首先删除div,然后显示我的弹出窗口.但在显示警报时,我能够看到div.关闭弹出窗口后,div将被删除.
$("#btnRemoveDiv").on("click",function(){$("#divRemove").remove();
alert("Removed");});Run Code Online (Sandbox Code Playgroud)
<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">Run Code Online (Sandbox Code Playgroud)
@quirimmo请看这个: