//遍歷元素節(jié)點(diǎn)
function walk(ele, walk, start, all) {
var el = ele[start || walk];
var list = [];
while (el) {
if (el.nodeType == 1) {
if (!all) return el;
list.push(el);
}
el = el[walk];
}
return all ? list : null;
}
//獲取上一個元素節(jié)點(diǎn)
function getPrev(ele) {
return ele.previousElementSibling || walk(ele, "previousSibling", null, false);
}
//獲取下一個元素節(jié)點(diǎn)
function getNext(ele) {
return ele.nextElementSibling || walk(ele, "nextSibling", null, false);
}
//獲取第一個元素子節(jié)點(diǎn)
function getFirst(ele) {
return ele.firstElementChild || walk(ele, "nextSibling", "firstChild", false);
}
//獲取最后一個元素子節(jié)點(diǎn)
function getLast(ele) {
return ele.lastElementChild || walk(ele, "previousSibling", "lastChild", false);
}
//獲取所有子元素節(jié)點(diǎn)
function getChilds(ele) {
return ele.children || walk(ele, "nextSibling", "firstChild", true);
}