Emptyfunction() {VarElem, i = 0;for (; (Elem =This[i])! =Null i++) {//Remove element nodes and prevent memory leaksif (Elem.nodetype = = = 1) {// loop erase data Jquery.cleandata (GetAll (Elem, false// remove child while (Elem.firstchild) {elem.removechild (elem.firstchild);} // If this was a select, ensure that it displays empty (#12336 ) // support:ie<9 if (Elem.options && jquery.nodename (elem, "select" )) {elem.options.length = 0
; }}
return this;},
In the code, all the data is erased first, so what does data contain?
The GetAll method finds all descendant elements. The GetAll code for jquery is as follows:
var strundefined =typeofUndefinedfunctionGetAll (context, tag) {VarElems, elem, i = 0, found =typeof Context.getelementsbytagname!== strundefined? Context.getelementsbytagname (Tag | | "*") :typeof Context.queryselectorall!== strundefined? Context.queryselectorall (Tag | | "*"): undefined; if (! Found) { for (found = [], Elems = Context.childnodes | | context; (Elem = Elems[i])! = null; i++ ) { if (!tag | | Jquery.nodename (Elem, tag)) {Found.push (elem);} else {jquery.merge (found, getAll (Elem, Tag));}}} return tag = = = Undefined | | Tag && jquery.nodename (context, tag)? Jquery.merge ([context], found): found;} GetAll (Document.body,false); htmlcollection Array
The collection to which GetAll is taken, cleandata
- Removeevent the event, freeing the memory (jquery-bound events are saved in data), and the code below can find the list of events we have bound. Expando is the identity of each object in jquery that is not duplicated in the page. expando: "JQuery" + (version + Math.random ()). Replace (/\d/g, ""),
$ (' body '). On (' click ',function() { alert (' The IS Body ');}); Console.log ($.cache[$ (' body ') [0][$.expando]]);
- Delete Internalkey (object ID), push ID to Deletedids
Simply empty, the first loop is to remove the bindings from the descendant elements, clear jquery to this Dom's cache, and loop removefirstchild.
and the HTML ("), is the simple brute force setting innerHTML = ';
Transferred from: http://www.cnblogs.com/henryli/archive/2014/02/25/3566461.html
jquery source of the empty and HTML (") difference