zoukankan      html  css  js  c++  java
  • javascript 的 appendChild用法

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>测试</title>
    </head>
    <body>
        <ul id="ul">
            <li>11</li>
            <li>22</li>
            <li>33</li>
            <li>44</li>
            <li>55</li>
        </ul>
        <input type="button" value="按钮" id="btn1">
        <input type="text" id="tex1">
        <script>
            window.onload=function(){
                var oUl=document.getElementById('ul');
                var aLi=document.getElementsByTagName('li');
                var oTex=document.getElementById('tex1');
                var oBtn=document.getElementById('btn1');
                oBtn.onclick=function(){
                    var oLi=document.createElement('li');
                    oLi.innerHTML=oTex.value;
                    if(aLi.length==0){
                        oUl.appendChild(oLi);    
                    }else{
                         oUl.insertBefore(oLi,aLi[0]);  //insertBefore('插入内容','在谁之前插入')
                    }
                    
                   
                }
            }
        </script>
    </body>
    </html>

  • 相关阅读:
    The jQuery UI CSS Framework(中文说明)
    锁定表头和固定列(Fixed table head and columns)
    html5学习二(canvas)
    浅析深究什么是SOA
    页面加载完毕后执行js函数的方法
    Spring AOP详解(转)
    db2move详解
    DB2 命令总汇
    Ubuntu下Apache的配置
    maven打包的一些问题
  • 原文地址:https://www.cnblogs.com/chabai/p/5139191.html
Copyright © 2011-2022 走看看