zoukankan      html  css  js  c++  java
  • innerHTML 和 innertext 以及 outerHTML

      今天在制作firefox下支持复制的js代码的时候,用到了innerText,测试发现原来firefox支持innerHTML但不支持innerText.

      test.innerHTML:
      也就是从对象的起始位置到终止位置的全部内容,包括Html标签。
      上例中的test.innerHTML的值也就是“<span style="color:red">test1</span> test2 ”。
      test.innerText:
      从起始位置到终止位置的内容, 但它去除Html标签
      上例中的text.innerTest的值也就是“test1 test2”, 其中span标签去除了。
      test.outerHTML:
      除了包含innerHTML的全部内容外, 还包含对象标签本身。
      上例中的text.outerHTML的值也就是<div id="test"><span style="color:red">test1</span> test2</div>

      这段加在你所JS文件中就可以在MOZILLA/FIREFOX下使用innerText

     
    HTMLElement.prototype.__defineGetter__ 
    ( 
    "innerText", 
    function () 
    { 
    var anyString = ""; 
    
    var childS = this.childNodes; 
    for(var i=0; i<childS.length; i++) 
    { 
    if(childS[i].nodeType==1) 
    anyString += childS[i].tagName=="BR" ? '
    ' : childS[i].innerText; 
    else if(childS[i].nodeType==3) 
    anyString += childS[i].nodeValue; 
    } 
    return anyString; 
    } 
    ); 
    
  • 相关阅读:
    UVA 10391 STL容器的使用
    UVA 10763
    UVA 10935
    UVA 洪水
    UVA 1594 set 里面放queue
    关于STL 容器的嵌套使用, 小试牛刀
    丑数 UVA 136
    UVA 1368 DNA
    antd 上传文件控件使用方法(坑)
    mysql查询一条工单时间需要10秒。优化sql语句得以解决。
  • 原文地址:https://www.cnblogs.com/isuben/p/3861122.html
Copyright © 2011-2022 走看看