zoukankan      html  css  js  c++  java
  • Javascript中appendChilid()内涵

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <style type="text/css">
            #ul1
            {
                background-color: green;
            }
    
            #ul2
            {
                background-color: yellow;
            }
        </style>
        <script type="text/javascript">
            window.onload = function () {
                var oBtn = document.getElementById("btnChange");
                var oUl1 = document.getElementById("ul1");
                var oUl2 = document.getElementById("ul2");
                var aLi = document.getElementsByTagName("li");
    
                //for (var i = 0; i < aLi.length; i++) {
                //    aLi[i].onclick = function () {
                //        oUl1.removeChild(this);
                //        oUl2.appendChild(this);
                //    }
                //} 
                oBtn.onclick = function () {
                    var oLi = oUl1.children[0];
                    oUl1.appendChild(oLi)
                    //oUl1.removeChild(oLi);
                    //oUl2.appendChild(oLi);//1.先把元素从原有的父级别上删掉,在添加到新的父级上
                }
            }
        </script>
    </head>
    <body>
        <ul id="ul1">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <input type="button" value="移动" id="btnChange" />
        <ul id="ul2">
        </ul>
    </body>
    </html>
    

      

  • 相关阅读:
    PHP Mysql-插入多条数据
    PHP Mysql-插入数据
    PHP Mysql-创建数据表
    PHP Mysql-创建数据库
    PHP Mysql-连接
    PHP Mysql-简介
    PHP-7
    postgresql 创建函数
    在psql客户端中修改函数
    修改PostgreSQL数据库的默认用户postgres的密码
  • 原文地址:https://www.cnblogs.com/alphafly/p/3780937.html
Copyright © 2011-2022 走看看