zoukankan      html  css  js  c++  java
  • DOM增删改操作

    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8">
    <title></title>
    <script>
    function create() {
    var mu = document.getElementById('u');
    var ele = document.createElement('li');
    ele.innerHTML = '4';
    //mu.appendChild(ele); //在末尾追加一个元素
    //mu.insertBefore(ele,mu.firstChild.nextSibling); //在指定位置插入元素
    //mu.replaceChild(ele,mu.firstChild.nextSibling); //指定位置替换元素
    }

    function copy() {
    var mu = document.getElementById('u');
    var ele = mu.firstChild.nextSibling.cloneNode(false);
    ele.innerHTML = 'a';
    mu.appendChild(ele);
    }

    function remove() {
    var mu = document.getElementById('u');
    var ele = mu.firstChild.nextSibling;
    mu.removeChild(ele);
    }
    </script>
    </head>

    <body>
    <ul id="u">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    </ul>

    <button value="1" onclick="create()">create</button><br />
    <button value="2" onclick="copy()">copy</button><br />
    <button value="3" onclick="remove()">remove</button>
    <hr />

    </body>

    </html>

  • 相关阅读:
    获取comboBox里面的item使用的方法
    QT格式化代码
    按键槽的写法
    int to String
    sprintf在51单片机中的使用
    学习使用MarkDown
    分享9款超酷的jQuery/CSS3插件
    2014年展望
    操作系统面试
    web一点小结
  • 原文地址:https://www.cnblogs.com/youcandomore/p/7239930.html
Copyright © 2011-2022 走看看