Analysis of three usage examples of Jquery-data

小云云
Release: 2018-01-17 15:06:20
Original
966 people have browsed it

This article mainly introduces three uses of Jquery-data. Has very good reference value. Let's take a look with the editor below, I hope it can help everyone.

Record

The use of Jquery-data:

jQuery-data is mainly used to store data and help ordinary objects or jQuery objects to store Data, in fact, if you simply store a single attribute of the dom, it is enough to use attr custom attributes; if you store multiple key-value pairs, it is recommended to use jQuery-data;

For example: Many plug-ins use this for lazy loading of images. When it comes to jquery-data, first store the real address of the picture in jquery-data, make a monitoring event, and then take out the real address when you slide to the picture;

Usage 1: Give to ordinary people The object stores a single attribute and value


 var obj = {}; $.data(obj, 'name', 'xm'); // 赋值 var str = $.data(obj, 'name'); // 读取值 console.log(str) // "xm"
Copy after login

Usage 2: Store multiple attributes and values for ordinary objects


 var obj = {}; $.data(obj,{name1:"xm",name2:"xh"}); // 赋值 var str1 = $.data(obj, 'name1'); // 读取值 var str2 = $.data(obj, 'name2'); // 读取值 console.log(str1) // "xm" console.log(str1) // "xh"
Copy after login

Usage 3: Assign value to Jquery dom object

var obj = $('.demo'); $.data(obj,{name1:"xm",name2:"xh"}); // 赋值 var str1 = $.data(obj, 'name1'); // 读取值 var str2 = $.data(obj, 'name2'); // 读取值 console.log(str1) // "xm" console.log(str1) // "xh" // 就是把obj换成jquery对象这么简单
Copy after login

Related recommendations:

PHP How to solve the problem of Chinese garbled characters in MySQL stored data

Detailed introduction to stored data

html5 Detailed explanations of several examples of storing data on the client

The above is the detailed content of Analysis of three usage examples of Jquery-data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!