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>
    

      

  • 相关阅读:
    iOS中图片与视频一次性多选
    UIImagePickerController Class
    1月16日
    10月20日
    1月14日
    1月13日
    1月12日
    1月11日
    课程评价与建议
    加分总结
  • 原文地址:https://www.cnblogs.com/alphafly/p/3780937.html
Copyright © 2011-2022 走看看