zoukankan      html  css  js  c++  java
  • 火狐模拟outerHTML

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    </head>

    <body><input name="" type="text" id="ss1" />
    </body>
    </html>
    <script>
    /*outerHTML for Firefox*/
    if(typeof(HTMLElement)!="undefined" && !window.opera)
    {
    HTMLElement.prototype.__defineGetter__(
    "outerHTML",function()
    {
    var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
    if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
    if(!this.canHaveChildren) return str+" />";
    return str+">"+this.innerHTML+"</"+this.tagName+">";
    });
    HTMLElement.prototype.__defineSetter__(
    "outerHTML",function(s)
    {
    var d = document.createElement("DIV"); d.innerHTML = s;
    for(var i=0; i<d.childNodes.length; i++)
    this.parentNode.insertBefore(d.childNodes[i], this);
    this.parentNode.removeChild(this);
    });
    HTMLElement.prototype.__defineGetter__(
    "canHaveChildren",function()
    {
    return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
    }
    /*end outerHTML*/
    alert(document.getElementById('ss1').outerHTML);
    txt
    = document.getElementById('ss1').outerHTML;
    document.getElementById(
    'ss1').outerHTML = txt + '13';
    alert(document.getElementById(
    'ss1').outerHTML);
    </script>

    不是很好用,可以读取,也可以赋值,但不可以追加

    有机会好好研究

    /*outerHTML for Firefox*/
  • 相关阅读:
    bs4抓取糗事百科
    数据结构(复习排序算法)——选泡插(选择,冒泡,插入,希尔)
    Hive-ha (十三)
    Hive优化(十一)
    Hive压缩和存储(十二)
    Hive权限管理(十)
    Hive的视图和索引(九)
    Hive动态分区和分桶(八)
    Hive(七)Hive参数操作和运行方式
    Redis 基础
  • 原文地址:https://www.cnblogs.com/ShepherdIsland/p/1727753.html
Copyright © 2011-2022 走看看