zoukankan      html  css  js  c++  java
  • 获取/修改元素文本

    /*
     一个参数,返回元素的textContent或者innertext
     两个参数,用value参数的值设置元素的textContent或者innerText
    */
    
    function textContent(element, value) {
        var content = element.textContent; //检测textContent是否有定义
        if (value !== undefined) { //没有传递value,因此返回当前文本
            if (content !== undefined) {
                return content;
            } else {
                return element.innerText; //IE
            }
        } else { //传递了value,因此设置文本
            if (content !== undefined) { element.textContent = value };
            else element.innerText = value; //IE
        }
    }
    
    
    
    
    // 查找元素的后代中节点中的所有Text节点
    
    //返回天涯不是有e的纯文本内容递归进入其子元素
    //该方法类似与textContent属性
    
    //CDATASection节点----它是Text的子类型,代表了CDATA段的内容
    function getTextContent(argument) {
        var child, type, s = '';
        for (child = e.firstChild; child != null; child = child.nextSibling) {
            type = child.nodeType;
            if (type === 3 || type === 4) { //text和CDATASection节点
                s += child.nodeValue;
            } else if (type === 1) {
                s += getTextContent(child);//递归Element
            }
            return s;
        }
    }
  • 相关阅读:
    android 网络 post get
    java 命名规范
    android 判断service是否开启
    android 无线连接eclipse
    eclipse jar java.lang.NoClassDefFoundError
    eclipse 默认 utf8
    timer timetask handler
    android 自定义动画按钮
    设计网站
    java 分解arraylist中单个对象 的属性名与值
  • 原文地址:https://www.cnblogs.com/superZz/p/5839503.html
Copyright © 2011-2022 走看看