萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> 腳本Html教程 >> 創建HTML5新標簽(IE6~8)

創建HTML5新標簽(IE6~8)

  document.createelement能創建html5的新標簽,但動態創建尤其是元素時,還是用innerhtml比較適合。不過ie的innerhtml存在大量的問題,style,link ,script就需要特殊方法去生成。這種方法又將用於我們html5的新元素的創建!見下面例子:

<!doctype html>
<html>
  <head>
    <title>動態創建html5元素 by 司徒正美</title>
    
    <script>
  
      var div = document.createelement("div");

      div.innerhtml = "<section>section</section>";

      alert( div.innerhtml ); // "section</section>" in ie6~ie8

           
    </script>
</head>
<body>
動態創建html5元素 by 司徒正美
</body>
</html>

代碼二

<!doctype html>

<html>
  <head>
    <title>動態創建html5元素 by 司徒正美</title>
    
    <script>
  
      var div = document.createelement("div");
        div.innerhtml = "fixie<div>" +"<section>section</section>" +"</div>";
        alert(div.innerhtml );

        alert( div.lastchild.innerhtml );

           
    </script>
</head>
<body>
動態創建html5元素 by 司徒正美
</body>
</html>

copyright © 萬盛學電腦網 all rights reserved