国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

javascript 節(jié)點(diǎn)遍歷函數(shù)

2019-11-21 00:38:03
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
火狐官網(wǎng)上找到的一組函數(shù),相當(dāng)于treeWalker,有了它可以方便地在IE實(shí)現(xiàn)Traversal API 2的所有功能(nextElementSibling,previousElementSibling,firstElementChild,lastElementChild,children)These functions let you find the next sibling, previous sibling, first child, and last child of a given node (element). What makes them unique is that they safely ignore whitespace nodes so you get the real node you're looking for each time.
復(fù)制代碼 代碼如下:

function is_all_ws(nod) { return !(/[^/t/n/r ]/.test(nod.data)); }
function is_ignorable(nod) { return (nod.nodeType == 8) || ((nod.nodeType == 3) && is_all_ws(nod)); }
function node_before(sib) {
while ((sib = sib.previousSibling)) {
if (!is_ignorable(sib)) return sib;
}
return null;
}
function node_after(sib) {
while ((sib = sib.nextSibling)) {
if (!is_ignorable(sib)) return sib;
}
return null;
}
function first_child(par) {
var res = par.firstChild;
while(res) {
if(!is_ignorable(res)) return res;
res = res.nextSibling;
}
return null;
}
function last_child(par) {
var res = par.lastChild;
while(res) {
if(!is_ignorable(res)) return res;
res = res.previousSibling;
}
return null;
}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜兰市| 安达市| 田阳县| 平度市| 陈巴尔虎旗| 四子王旗| 民丰县| 芷江| 建阳市| 高碑店市| 石楼县| 合川市| 绥棱县| 台东县| 南通市| 麻城市| 鹤岗市| 皋兰县| 碌曲县| 大石桥市| 弥勒县| 天镇县| 吉安市| 宜州市| 水城县| 黔江区| 长岛县| 连平县| 鹤峰县| 南安市| 太原市| 中山市| 永吉县| 鄯善县| 沾化县| 长顺县| 镇坪县| 时尚| 托克逊县| 化德县| 通道|