您现在的位置: 万盛学电脑网 >> 程序编程 >> 网页制作 >> 脚本Html教程 >> 正文

创建HTML5新标签(IE6~8)

作者:佚名    责任编辑:admin    更新时间:2022-06-22

  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>