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

xiaoxiao2021-02-28  140

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>
转载请注明原文地址: https://www.6miu.com/read-35498.html

最新回复(0)