Three ways to use Jquery-data

Source: Internet
Author: User

The use of Jquery-data:

Jquery-data is mainly used to store data, to help ordinary objects or jquery objects to store data, in fact, if the simple storage of the DOM single attribute, with attr custom attributes enough, if the storage of multiple key value pairs is recommended jquery-data;

For example: The image of lazy loading a lot of plug-ins to use the Jquery-data, first the real address of the picture stored in the Jquery-data, do a listening event, until the slide to the image of the real address to take out;

Usage One: storing individual attributes and values for normal objects

1 <  type= "Text/javascript"  src= "Jquery-3.0.0.min.js"></ Script > 2 var obj = {}; 3 $.data (obj, ' name ', ' XM ');//Assignment 4 var str = $.data (obj, ' name ');//Read Value 5  Console.log (str)//"XM"

Usage two: Store multiple attributes and values for a normal object

<type= "Text/javascript"  src= "Jquery-3.0.0.min.js"> </script>var obj = {}; $.data (obj,{name1: "XM", Name2: "XH"});//assignment var str1 = $.data (obj , ' name1 '); Read Value  var str2 = $.data (obj, ' name2 ');//Read Value Console.log (STR1)//"XM" Console.log (STR1)//"XH"

Usage three: Assigning values to jquery DOM objects

<class= "Demo"></div><   type= "Text/javascript"  src= "Jquery-3.0.0.min.js"></  script>var obj = $ ('. Demo '); $.data (obj,{name1: "XM", Name2: "XH"});//assignment var str1 = $ . Data (obj, ' name1 '); Read Value  var str2 = $.data (obj, ' name2 ');//Read Value Console.log (STR1)//"XM" Console.log (STR1)//"XH"//is to replace obj with jquery object So Simple

Three ways to use Jquery-data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.