gpt4 book ai didi

asp.net - 当元素被销毁并重新创建时移动 jQuery data()

转载 作者:行者123 更新时间:2023-12-01 01:30:08 27 4
gpt4 key购买 nike

有人能想到一种(最好是快速的)方法将附加到 DOM 元素的 data() 移动到其自身的新实例吗?

我使用的灯箱插件删除并重新附加元素到页面,以便在灯箱中显示它(以避免 ASP.net 的多 ID 问题),显然是 .data()当发生这种情况时,附加到元素的信息就会丢失。

最佳答案

您可以使用 .clone() 一个相对较新的重载来执行此操作。

.clone(true) 将复制具有完整事件和数据的元素。

或者,将您的插件更改为使用 .detach()而不是保持数据完整的 .remove() 。来自文档:

The .detach() method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

关于asp.net - 当元素被销毁并重新创建时移动 jQuery data(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2544674/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com