jQuery table td可编辑

参考链接:

  http://www.freejs.net/

  http://www.freejs.net/article_biaodan_34.html

  http://www.freejs.net/search.php?keywords=%E7%BC%96%E8%BE%91

效果图:

 源代码:

<!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>jQuery table td可编辑</title>
    <style type="text/css">
        /*
         * page css
         */
        a,body,center,code,dd,div,dl,dt,em,fieldset,form,h1,h2,h3,h4,h5,h6,html,i,img,label,li,ol,p,pre,small,span,strong,sub,sup,u,ul {
            margin: auto;
            padding: 0;
            border: 0;
            outline: 0;
            font-size: 100%;
            vertical-align: baseline;
            background: 0 0
        }

        h2 {
            text-align: center;
            padding: 10px;
            font-size: 20px
        }

        a {
            color: #007bc4;
            text-decoration: none
        }

        a:hover {
            text-decoration: underline
        }

        ol,ul {
            list-style: none
        }

        table {
            border-collapse: collapse;
            border-spacing: 0
        }

        body {
            height: 100%;
            font: 12px;
            color: #51555C;
            background: #2C2C2C
        }

        img {
            border: none
        }

        .logo {
            width: 910px
        }

        #main_demo {
            width: 910px;
            min-height: 600px;
            margin: 30px auto 0 auto;
            background: #fff;
            -moz-border-radius: 12px;
            -khtml-border-radius: 12px;
            -webkit-border-radius: 12px;
            border-radius: 12px
        }

        .ad {
            text-align: center;
            margin-top: 25px
        }

        .clear {
            clear: both
        }

        /*
         * demo styles
         */
         table {
            margin: 0 auto;
            border-collapse: collapse
        }

        td,th {
            width: 10%;
            font-size: 14px;
            padding: 10px 0;
            text-align: center;
            border: 1px solid #ddd
        }

        th {
            background-color: #f4f4f4
        }

        /* 
         * input
         */
         td.input {
            position: relative
        }

        td input {
            width: 100%;
            border: 1px solid #CF5C74;
            background: #F90;
            border-radius: 4px;
            display: block;
            position: absolute;
            text-align: center;
            font-size: 14px;
            left: 0;
            top: 0;
            padding: 11px 0;
            margin: -1px 0 0 -1px
        }

        td.hover {
            background: #eee
        }
    </style>
</head>
<body>
    <div id="main_demo">
        <h2>jQuery table td可编辑</h2>
        <table border="0" cellpadding="0" cellspacing="0" width="500">
            <tbody>
                <tr>
                    <th>td input演示</a></th>
                    <th scope="col">列1</th>
                    <th scope="col">第二列</th>
                    <th scope="col">其他</th>
                </tr>
            </tbody>
            <tbody>
                <tr>
                    <th>1</th>
                    <td class="content"></td>
                    <td class="text"></td>
                    <td class="position">0</td>
                </tr>
                <tr>
                    <th>2</th>
                    <td class="content"></td>
                    <td class="text">0</td>
                    <td class="position">0</td>
                </tr>
                <tr>
                    <th>3</th>
                    <td class="content"></td>
                    <td class="text"></td>
                    <td class="position hover">0</td>
                </tr>
            </tbody>
        </table>
    </div>

    <!-- JS文件:jQuery-百度CDN -->
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $('table td').click(function() {
                if (!$(this).is('.input')) {
                    $(this).addClass('input').html('<input type="text" value="' + $(this).text() + '" />')
                        .find('input')
                            .focus()
                            .blur(function() {
                                $(this).parent().removeClass('input').html($(this).val() || 0);
                            });
                }
            }).hover(function() {
                $(this).addClass('hover');
            }, function() {
                $(this).removeClass('hover');
            });
        });
    </script>
</body>
</html>

^_^

转载于:https://www.cnblogs.com/gotodsp/p/8360156.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery Table 是一个开源的 jQuery 插件,用于在网页上创建漂亮的表格。它提供了许多功能,包括排序、搜索、分页、过滤、编辑等,使得表格的操作和展示更加方便、美观。 使用 jQuery Table 插件,你可以轻松地将任何一个 HTML 表格转换成一个更加功能强大的表格。它支持所有主流浏览器,并且具有良好的兼容性。 下面是一个简单的示例代码,演示如何使用 jQuery Table 插件: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jQuery Table Demo</title> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css"> </head> <body> <table id="myTable"> <thead> <tr> <th>Name</th> <th>Age</th> <th>City</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>25</td> <td>New York</td> </tr> <tr> <td>Jane</td> <td>30</td> <td>Los Angeles</td> </tr> <tr> <td>Bob</td> <td>35</td> <td>Chicago</td> </tr> </tbody> </table> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script> <script> $(document).ready(function() { $('#myTable').DataTable(); }); </script> </body> </html> ``` 在这个示例中,我们引入了 jQueryjQuery Table 插件的库文件,并创建了一个简单的 HTML 表格。然后,在 JavaScript 中,我们调用了 DataTable() 方法来将表格转换成一个可排序可搜索的表格。 运行代码后,你会看到一个漂亮的表格出现在网页上,并且你可以使用各种功能对表格进行操作和筛选。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值