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

首頁 > 語言 > JavaScript > 正文

javascript 節點遍歷函數

2024-05-06 14:10:47
字體:
來源:轉載
供稿:網友
火狐官網上找到的一組函數,相當于treeWalker,有了它可以方便地在IE實現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.
代碼如下:
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;
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 万荣县| 多伦县| 明溪县| 浮山县| 浪卡子县| 普陀区| 新津县| 白山市| 娄烦县| 青海省| 上林县| 阜阳市| 台中县| 石狮市| 永胜县| 汕头市| 黔西| 富阳市| 红原县| 万荣县| 汕尾市| 石棉县| 奎屯市| 商河县| 阿勒泰市| 涞源县| 崇信县| 贵阳市| 荣昌县| 霞浦县| 虹口区| 鹤峰县| 太仆寺旗| 旬阳县| 开封市| 乐都县| 彝良县| 于田县| 太保市| 广安市| 饶平县|