最佳答案
您只需将文本添加到 var
,然后删除单元格文本,然后追加 input
$(function(){
$(".input").click(function(){
if(!$(this).hasClass("typing")){
var text = $(this).text();
$(this).text("");
$(this).append('<input class="input" type="text" value="'+text+'">');
$(this).focus();
$(this).addClass("typing");
}else {
$(this).removeClass("typing");
}
});
})
.input {
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="input">
hello
</td>
<td class="input">
test
</td>
</tr>
</table>
关于jquery - 编辑内联数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50171397/