更新时间:2021-12-08 23:36:51
好的,找到解决方案谢谢发表到这篇文章: jQuery replaceWith find new element
Ok, found the solution thanks to this post: jQuery replaceWith find new element
似乎在替换后,对象从DOM中删除,因此创建了一个新对象。所以,我不得不改变这样的代码:
It seems that after replace with, the object is removed from the DOM, so a new one is created. So, I had to change the code like this:
$(".hotel_info").each(function () {
var div; var div2;
div = $(this);
div2 = div.replaceWithPush(data);
truncInfo(div2);
});
$.fn.replaceWithPush = function (a) {
var $a = $(a);
this.replaceWith($a);
return $a;
};
谢谢大家的时间!