jquery data方法
jquery.data()文档:http://api.jquery.com/jQuery.data/
html5有个data-*属性,跟这个功能一样。
Note: This is a low-level method; a more convenient .data() is also available.
The jQuery.data() method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore free from memory leaks. jQuery ensures that the data is removed when DOM elements are removed via jQuery methods, and when the user leaves the page. We can set several distinct values for a single element and retrieve them later:
jQuery.data( document.body, "foo", 52 );jQuery.data( document.body, "bar", "test" );Store then retrieve a value from the div element.
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.data demo</title>
<style>
div {
color: blue;
}
span {
color: red;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body> <div>
The values stored were
<span></span>
and
<span></span>
</div> <script>
var div = $( "div" )[ 0 ];
jQuery.data( div, "test", {
first: 16,
last: "pizza!"
});
$( "span:first" ).text( jQuery.data( div, "test" ).first );
$( "span:last" ).text( jQuery.data( div, "test" ).last );
</script> </body>
</html>
jquery对象 http://api.jquery.com/data/
.data( key, value )
$( "body" ).data( "foo", 52 );$( "body" ).data( "bar", { myType: "test", count: 40 } );$( "body" ).data( { baz: [ 1, 2, 3 ] } );$( "body" ).data( "foo" ); // 52$( "body" ).data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }jquery data方法的更多相关文章
- html 5 data-* (dataset) 属性和 jquery data方法比较
一些文章在介绍html 5 data-* (dataset)属性时,会提到jquery的data方法,认为data方法能够很好的利用html 5的这个特性.但实际上,二者的兼容性是很差的.下面给出一段 ...
- JQuery data方法的使用-遁地龙卷风
(-1)说明 我用的是chrome49,这个方法涉及到JQuery版本问题,我手里有3.0的,有1.9.1,后面将1.9.1及其以前的称为低版本,3.0称为高版本 测试例子用到的showMessage ...
- 转载 JQuery.data()方法学习
转载原地址 http://hanchaohan.blog.51cto.com/2996417/1271551 转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.ht ...
- jquery data方法取值与js attr取值的区别
<a data-v="3"></a> jquery data方法的运行机制: 第一次查找dom,使用attributes获取到dom节点值,并将其值存到缓存 ...
- jquery data方法获取某个元素上事件
获取某个元素上的事件,jquery的给元素绑定的事件可以用data方法取出来. 通过$(element).data("events")来获取 // 比如给一个button绑定两个c ...
- jQuery 数据 - jQuery.data() 方法
打印出 hi
- HTML5 自定义属性 data-* 和 jQuery.data 详解
新的HTML5标准允许你在普通的元素标签里,嵌入类似data-*的属性,来实现一些简单数据的存取.它的数量不受限制,并且也能由javascript动态修改,也支持CSS选择器进行样式设置.这使得dat ...
- jquery.data()&jquery.extend()
JQuery.data()方法 Jquery提供的在节点存取数据的方法. var $el = $('#app'); //使用键值对的方式存数据 $el.data('name', 'jinx'); $e ...
- Jquery 扩展方法实现原理
JSONP原理 首先:JSON和JSONP是不一样的概念. JSON是一种数据交换格式,而JSONP是非正式传输协议. 该协议的一个要点就是允许用户传递一个callback参数给服务端,然后服务端返回 ...
随机推荐
- 【转】关于C#使用Excel的数据透视表的例子
收到消息,下星期又有导出 Excel 报表的代码要写.心想,不就是 OleDb 先 CREATE 表, 然后 INSERT 么?都是体力活啊...... 结果拿到纸张的报表,我就悲剧了.报表的结构,像 ...
- ios专题 - 常用设计模式
设计模式:解决编程问题的设计模板 设计模式是一个抽象工具,用于面向对象的软件开发,以及其他领域.它是一个设计模板,在特定背景中,解决一般性的.重复出 现的问题.因此,设计模式是一种针对特定的.具体的设 ...
- 鼠标点击input时,placeholder中的提示信息消失
html代码: <input type="text" placeholder="多个关键词空格隔开"> 鼠标点击input时,placeholder ...
- lucene4.0 基于smb文件服务器的全文检索
使用lucene 4.0版本的全文检索 所需要的jar包 网速太慢,下次有空再把jar传上来 1.FileIndex 建立索引,查询,删除,更新 package com.strongit.tool ...
- JS函数的参数对象arguments在严格模式下的限制
在JS中,传入的函数的参数个数可以与定义函数的个数不一致,那么对于传入的实参的引用,则是arguments对象.然而改对象在严格模式和非严格模式下是由区分的: 1 在严格模式下arguments作为了 ...
- 【转】如何编译安装PHP扩展
本文参考 一开始安装PHP的时候,我们并不知道需要哪些扩展,所以只有等到我们真正用到的时候才想办法去安装. 安装PHP扩展最简单的办法就是 sudo apt-get install php5-xxx ...
- 基于Jquery的banner轮播插件,简单粗暴
新手练习封装插件,觉着在前端这一块的轮播比较多,各种旋转木马一类的3D旋转,技术不够,所以封装了一个简单的banner轮播插件,功能也比较简单,就是左右向的轮播. 先挂地址https://github ...
- jQuery.hhNewSilder 滚动图片插件
/** * jQuery.hhNewSilder 滚动图片插件 * User: huanhuan * QQ: 651471385 * Email: th.wanghuan@gmail.com ...
- Control character in cookie value, consider BASE64 encoding your value , java操作cookie遇到中文会报错的解决方案
项目当中用到cookie保存中文,但是会报如下错误: Control character in cookie value, consider BASE64 encoding your value 大概 ...
- 原创:Javascript循环队列类
需要滚动显示最多一定数量的信息,于弄了个这个 var LeesCircleQueue=function(size) { // 队列数组 var _queue=[]; // 队首索引 var _fron ...