将自定义数据存储在dom元素中 [英] Storing custom data in dom elements

查看:241
本文介绍了将自定义数据存储在dom元素中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错的吗?如果是这样,为什么?

  var elm = document.getElementById(myElm); 
elm.customValue = {attr1:test,attr2:test};

我了解如何使用数据属性,但我不想让我的dom所有这些属性。

解决方案

这在某些浏览器中引入了内存泄漏,因为您绑定了一个本机C对象(DOM元素)和一个JS对象在一起,一些垃圾收集算法不能处理这个。 IE是其中之一。



以下是关于IE内存泄漏的MSDN文章: http://msdn.microsoft.com/en-us/library/ie/bb250448(v = vs.85)的.aspx


Is this wrong? If so why?

var elm = document.getElementById("myElm");
elm.customValue = {attr1 : "test", attr2 : "test"};

I understand how to use the data attributes, but I don't want to muddy up my dom with all those attributes.

解决方案

This introduces a memory leak in some browsers because you bind a native C object (the DOM element) and a JS object together and some garbage collection algorithms cannot deal with this. IE is one of them.

Here is an MSDN article about IE memory leaks: http://msdn.microsoft.com/en-us/library/ie/bb250448(v=vs.85).aspx

这篇关于将自定义数据存储在dom元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆