zoukankan      html  css  js  c++  java
  • 动态改变dom结构常用方法

    动态改变dom结构常用方法

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>动态改变dom结构</title>
    </head>
        <script type="application/javascript">
            /*
            * 1.document.createElement();创建
            * 2.parentnode.appendChild();追加
            * 3.parentNode.removeChild();删除
            * 4.parentNode.insertBefore();插入
            * 5.parentNode.replaceChild();替换
            *
            *
            * */
    
            //1docuent.creatElement();
            function createle(){
                var obj=document.createElement("input");
                obj.type="text";
                console.log(obj);
            }
            function appendele(){
                var obj = document.createElement("input");
                obj.type="submit";
                var father = document.getElementById("fromer");
                father.appendChild(obj);
            }
            function removeele(){
                var father = document.getElementById("fromer");
                var child = document.getElementById("pwd")
                father.removeChild(child);
            }
            function insertele(){
                var father = document.getElementById("fromer");
                var child = document.getElementById("pwd");
                var newChild = document.createElement("input")
                father.insertBefore(newChild,child);
            }
            function replaceele(){
                var father = document.getElementById("fromer");
                var child = document.getElementById("pwd");
                var newChild = document.createElement("input");
                newChild.type="submit";
                father.replaceChild(newChild,child)
            }
        </script>
    <body>
    <button onclick="createle()">创建</button>
    <button onclick="appendele()">追加</button>
    <button onclick="removeele()">删除</button>
    <button onclick="insertele()">插入</button>
    <button onclick="replaceele()">替换</button>
    <hr/>
    <from id="fromer">
        用户名:<input type="text " name = "user"><br/>
        密码:<input id="pwd" type="password" name = "pwd"><br/>
        <input type="submit" value="提交" name="submit"><br/>
    </from>
    </body>
    </html>
    

      

  • 相关阅读:
    Pyhon基础过滤字符串中的字母数字特殊符号
    [编程题] 斐波那契数列
    左旋转字符串(Java)-循环Index方式
    [编程题]字符流中第一个不重复的字符
    6525. 【2020.4.1模拟】Valleys
    6515. 【GDOI2020模拟03.28】数一数(one)
    6516. 【GDOI2020模拟03.28】数二数(two)
    6508. 【GDOI2020模拟03.11】我的朋友们
    6494. 【GDOI2020模拟03.08】勘探
    6491. 【GDOI2020模拟03.04】铺路
  • 原文地址:https://www.cnblogs.com/heviny/p/10815873.html
Copyright © 2011-2022 走看看