jquery.data () method

On the div element first and then get the data storage

 

$ .Data () function is used to access data on a specified element returns the set value.

Tip:  1. This is a method bottom, .data () method is more convenient to use. 
2. data () function is accessed data are temporary data, once the page is refreshed, the data will be stored until removed. 
3. The method does not currently provide cross-platform settings in the XML document, Internet Explorer does not allow additional data through custom attributes in an XML document.

 

grammar

$.data( element, key, value )

  

 1. data () function to access the data are temporary data, once the page is refreshed, the data will be stored until removed.
2. undefined is not a data value identified. Call jQuery.data (el, "name", undefined) returns the "name" of the corresponding data, equivalent to jQuery.data (el, "name") .

We can set different values ​​on an element, and get these values:

jQuery.data(document.body, 'foo', 52); jQuery.data(document.body, 'bar', 'test');

Call jQuery.data (el, "name", undefined) returns the "name" of the corresponding data, equivalent to jQuery.data (el, "name").

We can set different values ​​on an element, and get these values:

 

example:

 var body = document.getElementsByTagName('body');
       $.data(body[0],'test',{age:21,username:'webcyh'});
 console.log($.data(body[0],'test'));

result:

 

Guess you like

Origin www.cnblogs.com/webcyh/p/11278583.html
Recommended