• 使用js添加div


    <!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;
            margin: 20px;
            }
        </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)
                 newNodeBottom.innerHTML = "dshdfoihouj";
    
            }
        </script>
    </head>
    <body>
        <div id="1">current DIV</div>
    </body>
    </html>

    <!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;        margin: 20px;        }    </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)             newNodeBottom.innerHTML = "dshdfoihouj";
            }    </script></head><body>    <div id="1">current DIV</div></body></html>

  • 相关阅读:
    Sublime_text 3 安装 Package Control
    sql server cross/outer apply 用法
    sql server pivot/unpivot 行列互转
    sql server利用开窗函数over() 进行分组统计
    小记sql server临时表与表变量的区别
    自己实现各种进制相互转换
    我这样理解js里的this
    js 数组去重
    分布式计算
    START法则
  • 原文地址:https://www.cnblogs.com/myfaith-feng/p/9569904.html
Copyright © 2020-2023  润新知