(-1) description
I'm using chrome49, this method involves the jquery version problem, I have 3.0 in my hand, 1.9.1, then 1.9.1 and the previous one is called the lower version, 3.0 is called the high version
The showmessage method used in the test example is as follows
showmessage.i = 0;
function ShowMessage (object)
{
var body = $ (' body ') [0];
var $p =$ ("#debugp");
if ($p. length==0)
{
$p = $ ("<p/>"). attr ("id", "DEBUGP");
$ (body). Prepend ($p);
}
$p [0].innerhtml + + <br/>] + (showattribute.i++) + | "+object;
}
(0) $.data (obj,key,value)
The key value is a string type, a number, object (Var lol={}), is meaningless, the value can be a normal type, and is passed as a reference rather than a clone when it is a reference type
A.
var obj = {"Name": "Ice Shooter", "Age": "12"};
$.data (obj, "height", 165);
ShowMessage ($.data (obj, "height"));
$.data actually put the data on the object properties, similar to the obj.sex= "female", whether you add a few keys to obj through $.data, in obj only one more similar to the jQuery300082932543555993442
300082932543555993442 is the random number generated by jquery, which points to an object that stores the data you add in the form of Key-value.
The lower version can traverse the for-in through the jQuery300082932543555993442, the high version can only be viewed through the Debug tool
B.
When value is an object, a reference is passed
var husband = ["King of Barbarians"];
var obj = {"Name": "Ice Shooter", "Age": "12"};
$.data (obj, "husband", husband);
$.data (Obj,husband) [0] = "dun tornado";
ShowMessage ($.data (Obj,husband));/Output tornado
(2) $ (selector). Data (Key,value)
$ ("#lol"). Data ("name", "Ice Shooter");
ShowMessage ($ ("#lol"). Data ("name");
$ (selector). Data binds to HTML DOM elements, and the remaining features are the same as the $.data method, but you can get the added objects by for-in
The use of this old jquery data method is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.