zoukankan      html  css  js  c++  java
  • javascript添加删除行信息

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StuInfo.aspx.cs" Inherits="StuManager.StuInfo" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Add Student Info</title>
        <style type="text/css">
            #div1
            {
                 300px;
                height: 300px;
                border: 1px;
            }
        </style>
        <script type="text/javascript">
            //执行删除
            function ben_delete(DelRow) {
                //获取点击的行的tr
                var tr = DelRow.parentNode.parentNode;
                //删除tbody中的子行
                document.getElementById('tbody1').removeChild(tr);
            }
            window.onload = function () {
                document.getElementById("btn_Save").onclick = function () {
                    //获取新行内容
                    var name = document.getElementById("name").value;
                    var age = document.getElementById("age").value;
                    var tbaleobj = document.getElementById("tbody1");
                    //在最上边添加一个新行
                    var addRow = tbaleobj.insertRow(-1);
                    //为新行插入数据
                    addRow.insertCell(-1).innerHTML = name;
                    addRow.insertCell(-1).innerHTML = name;
                    //将按钮添加到新行内
                    addRow.insertCell(-1).innerHTML = '<input type="button" id="btn_del" value="删除" onclick="ben_delete(this);"/>';
                };
            };
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <fieldset style="250px;">
            <div class="#div1">
                Name:<input type="TextBox" id="name" name="user_Name" value=" " /><br/>
                Age: <input type="TextBox"id="age" name="user_Age" value=" " /><br/>
                <input type="button" id="btn_Save" name="btn_Save" value="Save"  style="margin-left:180px;margin-top:-10px;""/>
            </div>
            </fieldset>
            <div>
                <table border="1px" style="220px;">
                    <thead>
                        <tr><td colspan="3">Student Info Table</td></tr>
                        <tr><td>Name</td><td>Age</td><td>Delete</td></tr>
                    </thead>
                    <tbody id="tbody1">
    
                    </tbody>
                </table>
    
            </div>
        </form>
    </body>
    </html>
    View Code
  • 相关阅读:
    保护【大数据】应用的步骤和工具
    提高UI设计效率的4个技巧
    你学会UI设计了吗?
    Android 零散知识点整理
    PHP面试和PHP开发者都应掌握的10个问题
    MySQL 中如何存储 emoji ?
    想在网上保持匿名?教你用Linux如何实现!
    数据库入门之运行原始 SQL 查找
    PHP之取得当前时间函数方法
    【在线】使用在线软件来完成任务
  • 原文地址:https://www.cnblogs.com/JueXiaoQiang/p/6819441.html
Copyright © 2011-2022 走看看