jquery cache(数据缓存)

jQuery的数据缓存,静态字段jQuery.cache/jQuery.uuid/jQuery.expando

提供了data/removeData 存储/删除数据

 

jQuery.extend({
    cache: {},
    uuid:
    expando            
});

 

jQuery.cache 空对象,用来缓存

jQuery.uuid 在最新1.9中删除了

jQuery.expando 每一个复制的jQuery独特标志,去掉了非数字,用在data时在HTMLElement或js对象上标志

方法使用

data方法 为HTMLElement和js对象 提供缓存

// 为HTMLElement提供缓存
$('#testCache').data("test", {first:16, last: "pizza!"});
$('#testCache span:first').text($("#testCache").data("test").first);
$('#testCache span:last').text($("#testCache").data("test").last);

// 为js对象提供缓存
var myObj = {};
$.data(myObj, 'name', 'jack');
console.log( $.data(myObj, 'name') );

如何存储

1 如何在HTMLElement中存储缓存,数据最终存储在jQuery.cache中

<div id="testCache"></div>
<script>
  var el = document.getElementById('testCache');
  $.data(el, 'test', "value");
  console.log(el[jQuery.expando]); // 1 
  console.log(jQuery.cache);	// {1: {data: {test:"value"}}};
</script>

2 在js对象中缓存,js直接用一个key来存储缓存对象,key是jQuery.expando

 

转载于:https://www.cnblogs.com/zzu-han/archive/2013/02/20/jquery-cache.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值