Three usage of jQuery-data

  • 的头像-Tumi
  • 47 day agopublish


jQuery-data is used:

jQuery-data is mainly used to store data to help normal objects or jQuery objects to store data, actually If a single properties of the DOM is sufficient, use the ATTR custom property; if you store multiple key values ​​to recommend jQuery-data;

, for example: the lazy loading of the picture is used to use jQuery- DATA, first store the real address of the picture to jQuery-data, make a monitoring event, etc., take the real address when you slip to the picture;

Usage 1: Store a single Attributes and value

 VAR OBJ = {}; $ .data (Obj, 'Name', 'XM'); / / Assign VAR STR = $ .data (Obj, 'Name'); // Read Value Console.log (STR) // "XM"     
Usage 2: Save multiple attributes and values ​​to ordinary objects

VAR OBJ = {}; $ .DATA (Obj, { Name1: “xm”, name2: “xh”}); // assignment var str1 = $ .data (obj, ‘name1’); // Read value var 2 = $ .data (obj, ‘name2’); // Read value console.log (str1) // “xm” console.log (str1) // “xh”
    Usage 3: Give jQuery DOM object value assignment  

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 so simple to replace the OBJ to jQuery object

 The above is all the contents of this article, hope The content of this article has a certain help to everyone's learning or work, and I hope to support Tumi cloud!  
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment