的html()是否会删除所有附加到被替换元素上的数据? [英] does jQuery's html() remove all data attached to elements that are replaced?
问题描述
我正在jQuery的帮助下显示选项卡式界面.单击选项卡时,ajax调用将使用
I'm displaying a tabbed interface with the help of jQuery. When you click a tab, a ajax call will replace all html from a $(".content")
element with new html, using something like
$(".content").html(response);
执行此操作时,是否已删除所有附加到.content
div内元素的jquery事件和函数?在替换HTML之后,可以再次触发这些事件和功能吗?如果我单击选项卡324523452354次,是否每次都会复制jQuery数据?
When I do this, are all jquery events and functions that are attached to elements inside the .content
div removed? Is it ok to fire these events and functions again after I replace the HTML ? If I click the tabs 324523452354 times, will it duplicate jQuery data every time?
推荐答案
是.它们将被删除.您可以使用直播事件将其附加到尚不存在的元素上.
Yes. They will be removed. You can use the live event to attach to elements that dont exist yet.
$(".myElementClass").live("click", function (e) {
e.preventDefault();
//do stuff
});
在这种情况下,无论何时将其插入到DOM中,都将始终在myElement
上调用此函数.
In this case, this function will always be called on myElement
no matter when it is injected into the DOM.
这篇关于的html()是否会删除所有附加到被替换元素上的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!