zoukankan      html  css  js  c++  java
  • 通过js修改doctype类型

    直接上代码啦:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
    <html> 
    <head> 
      <title>Untitled</title> 
    </head> 
    <body> 
    <script type="text/javascript"> 
    function foo() { 
      alert("document.body.parentNode.previousSibling.tagName\n" + document.body.parentNode.previousSibling.tagName); 
      alert("document.body.parentNode.parentNode.firstChild.tagName\n" + document.body.parentNode.parentNode.firstChild.tagName); 
      alert("document.body.parentNode.parentNode.firstChild.nodeName\n" + document.body.parentNode.parentNode.firstChild.nodeName); 
      alert("document.body.parentNode.parentNode.firstChild.nodeValue\n" + document.body.parentNode.parentNode.firstChild.nodeValue); 
      alert("document.body.parentNode.parentNode.lastChild.tagName\n" + document.body.parentNode.parentNode.lastChild.tagName); 
      alert("document.body.parentNode.parentNode.lastChild.nodeName\n" + document.body.parentNode.parentNode.lastChild.nodeName); 
    } 
    function redoctypeme(which) { 
      alert("before\n" + document.body.parentNode.parentNode.firstChild.nodeValue); 
      if(which == 1) { 
        document.body.parentNode.parentNode.firstChild.nodeValue = "DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\""; 
      } 
      else { 
        document.body.parentNode.parentNode.firstChild.nodeValue = "DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\""; 
      } 
      alert("after\n" + document.body.parentNode.parentNode.firstChild.nodeValue); 
      foobar = document.body.innerHTML; 
      alert("empty"); 
      document.body.innerHTML = ""; 
      alert("reset"); 
      document.body.innerHTML = foobar; 
    } 
    </script> 
    <a href="javascript: foo()">stuff</a> 
    <a href="javascript: redoctypeme('1')">doctype 1</a> 
    <a href="javascript: redoctypeme('2')">doctype 2</a> 
    <hr> 
    <div style="background: #0c0;  200px; color: #fff;">200px</div> 
    <div style="background: #c00;  200px; padding: 20px; border: 30px solid #00c;"> </div> 
    <div style="background: #0c0;  300px; color: #fff;">300px</div> 
    </body> 
    </html> 
    

      

  • 相关阅读:
    redis 基本类型命令
    吴寿仁 学术
    吴寿仁:上海科技成果转化40年
    从“四技”服务的收益中提取奖酬金是否不受当年本单位工资总额限制、不纳入本单位工资
    高校科技成果转化为什么就这样的难
    高校成果转换
    中华人民共和国 促进科技成果转化法
    上海市促进科技成果转化条例
    项目管理
    欧几里得方法计算最大公约数Python版本
  • 原文地址:https://www.cnblogs.com/jsfans/p/2295708.html
Copyright © 2011-2022 走看看