function parents(elem) {//elem 當前元素
var matched = [];// 翻譯=>匹配
while ((elem = elem['parentNode']) && elem.nodeType !== 9) {/*循環 1,給elem 賦值為其父節點2,判斷 如果 elem不等于根節點Document繼續循環 */if (elem.nodeType === 1) { matched.push(elem);} /* 3,如果elem nodeType 全等于 Element 將elem push 進匹配數組*/} return matched;
}
var matched = [];// 翻譯=>匹配
while ((elem = elem['parentNode']) && elem.nodeType !== 9) {/*循環 1,給elem 賦值為其父節點2,判斷 如果 elem不等于根節點Document繼續循環 */if (elem.nodeType === 1) { matched.push(elem);} /* 3,如果elem nodeType 全等于 Element 將elem push 進匹配數組*/} return matched;
}
// Descend through wrappers to the right content
// 因為warp被包裝過
// 需要找到正確的元素父級
j = wrap[0];
while (j--) {
tmp = tmp.lastChild;
}
這段代碼什么意思 為什么感覺看不懂
// 因為warp被包裝過
// 需要找到正確的元素父級
j = wrap[0];
while (j--) {
tmp = tmp.lastChild;
}
這段代碼什么意思 為什么感覺看不懂
2016-11-01
while循環有什么作用嗎?不理解啊
為什么要用jQuery.merge(nodes,tmp,childNodes);
nodes變量什么地方使用了?
為什么要用jQuery.merge(nodes,tmp,childNodes);
nodes變量什么地方使用了?
2016-10-26
這也太不嚴謹了,這一章突然加入classname讓人感到很迷,既然要filter掉className 那為什么不filter掉id呢?
2016-10-23
//創一個元素div做為容器
tmp = tmp || fragment.appendChild(context.createElement("div"));
...
jQuery.merge(nodes, tmp.childNodes);
大神這里還遺漏的有代碼。
通過jQuery.merge(nodes, tmp.childNodes)把碎片中的子節點添加到nodes中,但fragment沒有清除子節點。如果把fragment附加到dom節點,會保留這些未清楚的子節點。
應該在后面加上:
tmp = fragment.firstChild;
tmp.textContent = "";
tmp = tmp || fragment.appendChild(context.createElement("div"));
...
jQuery.merge(nodes, tmp.childNodes);
大神這里還遺漏的有代碼。
通過jQuery.merge(nodes, tmp.childNodes)把碎片中的子節點添加到nodes中,但fragment沒有清除子節點。如果把fragment附加到dom節點,會保留這些未清楚的子節點。
應該在后面加上:
tmp = fragment.firstChild;
tmp.textContent = "";
2016-10-08