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