• 添加删除


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script language="javascript" type="text/javascript">
          // 增加分类函数
          function addSort()
          {
             var name = document.getElementById("name").value;
              if(name == "" ) {
                    alert("请输入分类名称!");
                    document.getElementById("name").focus();
                    return;
              }
     
              var row = document.createElement("tr");
              row.setAttribute("id", name);
              var cell = document.createElement("td");
              cell.appendChild(document.createTextNode(name));
              row.appendChild(cell);
              
              var deleteButton = document.createElement("input");
              deleteButton.setAttribute("type", "button");
              deleteButton.setAttribute("value", "删除");
              deleteButton.onclick = function () { deleteSort(name); };
              cell = document.createElement("td");
              cell.appendChild(deleteButton);
              row.appendChild(cell); 
              document.getElementById("sortList").appendChild(row);
          //清空输入框
              document.getElementById("name").value = "";
          }
    
          // 删除分类函数
          function deleteSort(id)
          {
                if (id!=null)
                {
                       var rowToDelete = document.getElementById(id);
                       var sortList = document.getElementById("sortList");
                       sortList.removeChild(rowToDelete);
                }
          }
    
    </script>
    </head>
    
    <body>
    <div> <span>
      <input id="name" type="text" size="15">
      </span><span>
      <input type="button" id="submit1" value="添加" onclick="addSort();" />
      </span> </div>
    <!--<table style="400px; background-color:#99ccff;">
      <tbody>
        <tr>
          <td height="20"><input id="name" type="text" size="15"></td>
          <td height="20"><input type="button" id="submit1" value="添加" onclick="addSort();" /></td>
        </tr>
      </tbody>
    </table>-->
    <table style="border:1px solid #000000;" width="400">
      <tr>
        <td >分类名称</td>
        <td id="pos_1">操作</td>
      </tr>
      <tbody id="sortList" >
      </tbody>
    </table>
    </body>
    </html>
  • 相关阅读:
    python学习笔记十五-生成器
    python学习笔记十四-迭代器
    python学习笔记十三-装饰器
    The Zen of Python, by Tim Peters
    python学习笔记十二-函数
    python学习笔记十一-集合set
    tensorflow2 gpu 在 win10 上安装过程和问题处理
    anaconda navigator stuck 卡在 loading applications... 处理
    python工具pip加速For windows
    WCF With StructureMap
  • 原文地址:https://www.cnblogs.com/Xuman0927/p/5466066.html
Copyright © 2020-2023  润新知