zoukankan      html  css  js  c++  java
  • jQuery写电话簿

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style type="text/css">
            td {
                 100px;
            }
        </style>

    </head>

    <body>
        <div id="reg-input" style="margin-bottom:10px;">
            ID: <input type="text" id="user-id" />
            姓名: <input type="text" id="user-name" />
            电话: <input type="text" id="user-tel" />
            <button id="save">保存</button>
        </div>
        <table border="1" id="info-tbl">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>电话</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td>张三丰</td>
                    <td>13312345678</td>
                    <td><a href="#" class="del">删除</a></td>
                </tr>
                <tr>
                    <td>2</td>
                    <td>李四疯</td>
                    <td>13388888888</td>
                    <td><a href="#" class="del">删除</a></td>
                </tr>
            </tbody>
        </table>
        <script src="./lib/jquery-3.4.1.min.js"></script>
        <script>
            function save(){
                $('button').on('click',function(){

                    var $tr=$('<tr></tr>')
                    var $td_id=$('<td></td>')
                    $td_id.html($('#user-id').val())
                    var $td_name=$('<td></td>')
                    $td_name.html( $('#user-name').val())
                    var $td_tel=$('<td></td>')
                    $td_tel.html($('#user-tel').val())
                    var $td_remove=$('<td></td>')
                    $td_remove.html('<a href="#" class="del">删除</a>')


                    $td_id.appendTo($tr)
                    $td_name.appendTo($tr)
                    $td_tel.appendTo($tr)
                    $td_remove.appendTo($tr)
                    $tr.appendTo($('tbody'))

                    removeTR()

                })
            }
            save()


            function removeTR(){
                $('a').on('click',function(){
                    $(this).parent().parent().empty()
                })
            }
            removeTR()
        </script>
    </body>

    </html>
  • 相关阅读:
    (总结)CentOS Linux搭建SVN Server配置详解
    面试感悟----一名3年工作经验的程序员应该具备的技能
    SQL server 2008数据库的备份与还原(转)
    MyEclipse XX安装jad反编译插件
    c语言实现对传统单链表的创建、添加 遍历 删除 反转元素操作
    转>>Java工程师成神之路
    Programming reference for JavaScript
    elastic-job 的简单使用
    JAVA使用Ldap操作AD域
    nginx之location(root/alias)
  • 原文地址:https://www.cnblogs.com/plmmq/p/11707790.html
Copyright © 2011-2022 走看看