jQuery.data () method
Examples
On the div element to store and then retrieve data
try it"
Definition and Usage
$ .data () Function is used to access data on the specified elements, returns the set value.
Note: 1. This is a low-level method, .data () method is more convenient to use.
2. () function to access data are temporary data through data, refresh the page once, before storing the data will be removed.
3. This method is currently not available on XML cross-platform document settings, Internet Explorer is not allowed in XML documents through custom attributes additional data.
grammar
Use a
Note: 1. () function to access data are temporary data through data, refresh the page once, before storing the data will be removed.
2. undefined is a data value is not recognized. Call jQuery.data (el, "name", undefined) returns the corresponding "name" 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');
Use two
We can set different values on an element, and get these values:
alert(jQuery.data( document.body, 'foo' )); alert(jQuery.data( document.body ));
参数 | 描述 |
---|---|
element | Element类型 要存储数据的DOM对象 |
key | 可选。String类型 指定的键名字符串。 |
value | 可选。 Object类型 需要存储的任意类型的数据。 |
More examples
retrieve data
It is stored in the element named "blah" data.