This paper analyzes the usage of jquery data caching. Share to everyone for your reference. Specifically as follows:
In jquery's API Help document, jquery describes the role of data caching as a way to access data on one element to avoid the risk of circular references.
First, define cached data
Use the $ (selector). Data (Name,value) method to define cached data for jquery objects. These cached data are stored in all DOM elements in the collection of matching DOM elements.
var $link = $ (' a ');
$link. Data (' linktype ', ' home ');
Note: $ (selector). Data (Name,value) allows you to store any format on a matching DOM element, not just a string.
Second, get cached data
At this point, you need only one parameter that specifies the name of the cached data.
var linktype = $link. Data (' linktype '); ' Home '
Note: If the cached data read does not exist, the return value is undefined; if the jquery collection points to multiple elements, only the corresponding cached data for the first element will be returned.
Third, delete cached data
The Removedata () function deletes cached data for the specified name and returns the corresponding JQuery object.
When the cached data is deleted, the corresponding jquery object is returned.
var $a = $link. Removedata (' linktype ');
Four, the jquery data Cache usage Specification
With the number of calls to the data () function increased, or because of improper use, it will cause the cache object to expand dramatically, ultimately affecting the performance of the program.
So when using the jquery data caching feature, you should clean up cached objects in a timely manner. jquery provides the Removedata () function to manually purge cached data. Depending on the operating mechanism of the jquery framework, the following situations do not require manual cleanup of the data cache.
* The Remove () action is performed on the Elem, and jquery automatically clears the cache that the object may exist.
* Perform a empty () operation on Elem, and jquery also knows the possible data caches of child objects if there is a data cache for the current elem child element.
* The Clone () method of the jquery replication node does not replicate the data cache.
I hope this article will help you with your jquery programming.