The data API implementation of JQuery has the effect of caching
Using IE 7 (ie8+ in the console switch to IE7 mode), when the DOM node has custom data properties, the DOM node is examined to see the properties of the shape like jQuery18305664906559272507, which is the build that gets the custom data from the data store object.
When a custom data property is a JSON format string, if the cached data is modified, the modified data continues to exist in the cache system, which may cause some bugs if not noted
Copy Code code as follows:
<! DOCTYPE html>
<script src= "Http://code.jquery.com/jquery-1.8.3.js" ></script>
<body>
<input type= "hidden" value= "data-json= ' {" A ": 123," B ": 456} ' id= ' TST '/>
<script>
var node = $ ("#tst");
Console.log (node.attr ("Data-json"));
var data = Node.data ("JSON");
Console.log (data);
data.b = ' Hello ';
var data1 = Json.parse (node.attr ("Data-json"));
Console.log (DATA1);
Console.log (' data===data1 ', data===data1);
var data2 = Node.data ("JSON");
Console.log (DATA2);
Console.log (' Data===data2 ', data===data2);
var data3 = Json.parse (node.attr ("Data-json"))//This value is not affected by caching
Console.log (DATA3);
</script>
</body>
Run results
Copy Code code as follows:
{"A": 123, "B": 456}
Object {a:123, b:456}
Object {a:123, b:456}
Data===data1 false
Object {a:123, B: "Hello"}
Data===data2 true
Object {a:123, b:456}