<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Scriptsrc= "Jquery-2.0.3.js"></Script><Script>$(function(){ $('#div1'). attr ('name','Hello'); Alert ($ ('#div1'). attr ('name') ); document.getElementById ('Div1'). SetAttribute ('name','Hello'); Alert (document.getElementById ('Div1'). getattribute ('name') ); $('#div1'). Prop ('name','Hello'); Alert ($ ('#div1'). Prop ('name') ); document.getElementById ('Div1')['name'] = 'Hello'; Alert (document.getElementById ('Div1')['name'] ); $('#div1'). Data ('name','Hello'); Alert ($ ('#div1'). Data ('name') );});//DOM elements and objects are referenced to each other, and most browsers have memory leaksvarOdiv=document.getElementById ('Div1');varobj={};odiv.name=Obj;obj.age=Odiv;//A memory leak will occur$('#div1'). attr ('name', obj);//instead of worrying about memory leaks$('#div1'). Data ('name', obj); $ ('Body'). Data (' Age', obj);//data is the connection of DOM elements and objects indirectly through the cache. This prevents a memory leak. Such as. varCache= {// 1: {name:obj},2: {age:obj}};</Script></Head><Body><DivID= "Div1"XXX=" "></Div></Body></HTML>
JQuery11 data (): Cache