zoukankan      html  css  js  c++  java
  • 一次清空所有数据方法

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    </head>
    
    <body>
    <div id="content">
      <h1>1</h1>
      <h1>2</h1>
      <h1>3</h1>
      <h1>4</h1>
      <h1>5 </h1>
    </div>
    
    <script type="text/javascript">
    function clearText()
    {
        var content=document.getElementById("content");
        // 在此完成该函数
       
                 for(var i=0;0<content.children.length;i++) //content.children.length是个随i变化的量,每次i循环,content.children.length都减1
                  /*for (var i=content.childNodes.length-1;i>=0;i--) {
     var childNode = content.childNodes[i];
     content.removeChild(childNode); */  //使用此语句是因为content.children.length是个变量,可以放在开始,然后条件为i,此为倒序。数组不变的话使用正序和倒序都行,数组发生变化的时候使用倒序比较好。
              {
                //alert(content.children.length);
                //alert(content.children[0]);
                content.removeChild(content.children[0]);       //content.children[0]是移出后的content的第一个元素
                //alert(content.children[0]);
              };
    };
    </script> 
    <button onclick="clearText()">清除节点内容</button>
    </body>
    </html>
    View Code
    努力但不功利~~!
  • 相关阅读:
    Android安装apk
    Android获取应用程序版本信息
    Handler消息传递机制
    Activity的启动模式
    cocopods的使用
    ios9 的新特性
    静态库的制作详解
    真机调试
    时间差计算(给定两时间,转换为时间差)
    socket 通信机制的实现
  • 原文地址:https://www.cnblogs.com/langlang149/p/5626980.html
Copyright © 2011-2022 走看看