之前做了一个项目,不能用jquery写代码,只能用原生的js写插入,代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <style>
        div {
        border:solid 1px #ff0000;
        }
    </style>
    <script >
        window.onload = function () {
            
            var vtop = "js插入上面";
            var vcenter = "js中插入";
            var vbottom = "js插入下面";
            var vcurrent = document.getElementById("1");
            //上面
            var newNodeTop = document.createElement("div");
            newNodeTop.innerHTML = vtop;
            vcurrent.parentNode.insertBefore(newNodeTop, vcurrent);
            //中间
            var newNodeCenter = document.createElement("div");
            newNodeCenter.innerHTML = vcenter;
            vcurrent.appendChild(newNodeCenter);
            //下面
            var newNodeBottom = document.createElement("div");
            newNodeBottom.innerHTML = vbottom;
            vcurrent.parentNode.insertBefore(newNodeBottom, vcurrent.nextSibling)

        }
    </script>
</head>
<body>
    <div id="1">current DIV</div>
</body>
</html>

  

 

posted on 2017-05-02 10:51  cxd1008  阅读(26030)  评论(1编辑  收藏  举报