jQuery.data()存储在哪里?

jQuery.data()存储在哪里?

问题描述:

jQuery在哪里存储它设置为DOM对象的 data()的值?

Where does jQuery store the values of the data() that it sets to DOM objects?

是有某种变量,如 jQuery.dataDb 或其他东西,甚至可能是私有的?

Is there some kind of variable like jQuery.dataDb or something, maybe even something private?

有没有办法获取对此对象的访问权限?

Is there any way to gain access to this object?

在内部,jQuery创建一个名为 $ .cache的空对象,用于存储通过数据方法设置的值。您向其添加数据的每个DOM元素都会被分配一个唯一的ID,该ID在 $ .cache 对象中用作键。

Internally, jQuery creates an empty object called $.cache, which is used to store the values you set via the data method. Each DOM element you add data to, is assigned a unique ID which is used as a key in the $.cache object.