之前做了一个项目,不能用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>
本文为博主原创文章,欢迎转载,但转载须注在明显位置注明【博客地址】和【原文地址】,否则将追究法律责任。http://www.cnblogs.com/cxd1008