table可编辑表格写法(简单)

来源:互联网 发布:杭州市网络作家协会 编辑:程序博客网 时间:2024/05/29 19:22

1、添加JS

$(".table").find(".dbclicktd").bind("dblclick", function () {        var input = "<input type='text' id='temp' style='width:130px;' value=" + $(this).text() + " >";        $(this).text("");        $(this).append(input);        $("input#temp").focus();        $("input").blur(function () {            if ($(this).val() == "") {                $(this).remove();            } else {                $(this).closest("td").text($(this).val());            }        });    });

2、给要编辑的td加class就可 。

<td class="dbclicktd"></td>
1 0