zoukankan      html  css  js  c++  java
  • DOM操作

    function parent(e, n){
                var n = n || 1;
                while(n-- && e){
                    e = e.parentNode();
                }
                if(!e || e.nodeType != 1){
                    return null;
                }
                return e;
            }
            function sibling(e, n){
                while(e && n !==0){
                    if(n > 0){
                        if(e.nextElementSibling){
                            e = e.nextElementSibling;
                        } else{
                            for(e = e.nextSibling; e && e.nodeType !== 1; e = e.nextSibling);
                            /*empty loop*/
                        }
                        n--;
                    } else{
                        if(e.previousElementSibling){
                            e = e.previousElementSibling;
                        } else{
                            for(e = e.previousSibling; e && e.nodeType !== 1; e = e.previousSibling);
                            /*empty loop*/
                        }
                        n++
                    }
                }
                return e;
            }
            function textContent(element, value){
                var content = element.textContent;
                if(value !== undefined){
                    if(content !== undefined){
                        content = value;
                    } else{
                        element.innerText = value;
                    }
                } else{
                    if(content !== undefined){
                        return content;
                    } else{
                        return element.innerText;
                    }
                }
            }
            function textContent(e){
                var child, type, s = '';
                for(child = e.firstChild; child != null; child = child.nextSibling){
                    type = child.nodeType;
                    if(type == 3 || type == 4){
                        s += child.nodeValue;
                    } else if(type == 1){
                        s += textContent(e);
                    }
                }
                return s;
            }
  • 相关阅读:
    易语言常用源码
    ci的数据库地址
    格式化输出php数组
    mysql插入表情问题
    线程、进程与协程2
    线程、进程与协程
    if __name=='__main__"的作用
    动态导入模块
    面向对象补充之方法
    getpass模块
  • 原文地址:https://www.cnblogs.com/fanhc/p/3284128.html
Copyright © 2011-2022 走看看