jQuery .data()如何工作? [英] How does jQuery .data() work?

查看:129
本文介绍了jQuery .data()如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中使用.data(). 示例很有帮助,但是我不明白这些值的存储位置.

I want to use .data() in my application. The examples are helpful, but I do not understand however where the values are stored.

我用Firebug检查了网页,.data()将对象保存到dom元素后,我看不到Firebug中的任何更改(HTML或Dom选项卡).

I inspect the webpage with Firebug and as soon as .data() saves an object to a dom element, I do not see any change in Firebug (either HTML or Dom tabs).

我试图查看jQuery的源代码,但是由于我的Java知识非常先进,所以我迷失了自己.

I tried to look at jQuery source, but it is very advanced for my Javascript knowledge and I lost myself.

所以问题是:

由jQuery.data()存储的值实际上在哪里?我可以使用工具检查/定位/列出/调试它们吗?

Where do the values stored by jQuery.data() actually go? Can I inspect/locate/list/debug them using a tool?

推荐答案

看看来源.

快速浏览一下,就好像是将数据存储在第2行上创建的cache变量中一样.

From a quick glimpse, it looks like it's storing the data in that cache variable that is created on line 2.

下面是一个快速演示,可在缓存中查找数据: http://jsfiddle.net/CnET9/

Here's a quick demo that finds the data in the cache: http://jsfiddle.net/CnET9/

您还可以将$.cache转储到控制台并手动进行浏览.

You can also dump $.cache to your console and explore it manually.

这篇关于jQuery .data()如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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