zoukankan      html  css  js  c++  java
  • js 动态添加表单 table tr

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>js 动态添加表单</title>
    	<script src="scripts/jquery-1.7.1.min.js"></script>
    
    </head>
    <body>
    <script type="text/javascript">
    $(function(){
        // 提交按钮添加 click事件
        $("#addBtn").click(function(){
            // 获取form的值
            var name = $("input[name='name']").val();
            var email = $("input[name='email']").val();
            var phone = $("input[name='phone']").val();
            // 在table 中生成tr 
            var tr = $("<tr><td>"+name+"</td><td>"+email+"</td><td>"+phone+"</td><td><a href='#' onclick='deleteItem(this);'>删除</a></td></tr>");
            $("table").append(tr);
            // form重置,清除刚才表单填写的内容
            $("form")[0].reset();
        });
    });
    // 删除
    function deleteItem(a){
        // 删除 a 元素所在行 
        $(a).parents("tr").remove();
    }
    </script>
    <div align="center">
            <h3>添加表单</h3>
            <form>
                姓名 <input type="text" name="name" />
                邮箱 <input type="text" name="email" />
                电话 <input type="text" name="phone" /> 
                 <input type="button" value="提交" id="addBtn" />
            </form>
            <hr/> 
            <table border="1">
                <tr>
                    <th>姓名</th>
                    <th>email</th>
                    <th>电话</th>
                    <th>删除</th>
                </tr>
            </table>
        </div>
    </body>
    </html>
    

      

  • 相关阅读:
    第0课
    学前班-怎么看原理图
    LCD-裸机韦东山
    学前班
    专题8-Linux系统调用
    专题4-嵌入式文件系统
    网络编程 之 软件开发架构,OSI七层协议
    反射、元类,和项目生命周期
    多态、魔法函数、和一些方法的实现原理
    封装,接口,抽象
  • 原文地址:https://www.cnblogs.com/arealy/p/7736884.html
Copyright © 2011-2022 走看看