jQuery可实时编辑修改的表格table

来源:https://www.sucaihuo.com/js/834.html 2016-03-07 20:36浏览(3759) 收藏

jQuery点击表格任何元素都可编辑修改该数值,用户体验非常好。
jQuery可实时编辑修改的表格table
分类:表单代码 > 表格 难易:初级
查看演示 下载资源 下载积分: 20 积分
关注公众号,免费赠送安装视频教程、环境和学习视频,后面会不断更新。

jQuery点击表格元素

$(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');
    });
});

表格html代码

<table>
    <caption>2009年员工产品销售走势图</caption>
    <thead>
        <tr>
            <td></td>
            <th scope="col">food</th>
            <th scope="col">auto</th>
            <th scope="col">household</th>
            <th scope="col">furniture</th>
            <th scope="col">kitchen</th>
            <th scope="col">bath</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th scope="row">Mary</th>
            <td>190</td>
            <td>160</td>
            <td>40</td>
            <td>120</td>
            <td>30</td>
            <td>70</td>
        </tr>	
    </tbody>
</table>
标签: table表格
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2