实现prependChild方法,即appendChild的相对方法

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>New Web Project</title>
        <style type="text/css">
            span{
                color: #66A300;
                font-family: "Arial Black";
            }
        </style>
    </head>
    <body>
         <div id="main">
             <span>hello!</span>
         </div>
         
         <script type="text/javascript">
             Node.prototype.prependChild = function (newNode){
                 this.insertBefore(newNode,this.firstChild);
             }
             
             var main = document.getElementById("main");
             var node = document.createElement("span");
             node.innerHTML = "World,";
             main.prependChild(node);
         </script>
    </body>
</html>
原文地址:https://www.cnblogs.com/yingsmirk/p/2438787.html