0
我试图在使用remove()
函数删除html后添加元素。由于某种原因,当我调用add()
函数时,删除变量会丢失html DOM。如果我将remove.insertAfter('#element');
放在ajaxSuccess()之外,它就可以工作。我使用ajaxSuccess(),因为我希望ajax先完成,然后才能再次向用户显示元素。使用detach后无法添加html元素
var remove;
function remove() {
//there is a ajax call here
$(document).ajaxSuccess(function() {
remove = $('#myDiv').detach(); //or should I use remove()?
});
}
function add() {
//there is an ajax call here
$(document).ajaxSuccess(function() {
remove.insertAfter('#main');
});
}
<div id="main">
<div id="myDiv">
</div>
</div>
为什么一切都包裹在'ajaxSuccess'处理程序中,这不是要走到这里的路!发布ajax代码! – adeneo 2015-04-02 21:37:04