我在jquery表中很新。我有一个代码,将在我单击的某个列中添加文本输入。就我而言,该列是第9位.Below是我的代码:
$('#PtptnFileTblId_1').on( 'click', 'tbody td:not(:first-child)', function (e) {
var id = $(this).attr('id');
var file_id = $(this).attr('name');
var code = $(this).text();
var textrowId = $(this).children("td:nth-child(9)");
textrowId.html("<input type='text' id='callerid' name='callerid' style='width:100px;' value=''/>");
} );
点击某一行后,我希望它的第9列将添加一些文本字段,使我能够编辑其文本,但问题是我的代码似乎无法正常工作。在此之前,我使用相同的代码,但不同的方式,它的工作。请帮助我上面的代码。任何帮助将非常感谢
答案 0 :(得分:0)
在您的事件处理程序中,$(this)
指的是单击的单元格。您可以使用closest('TR')
检索表格行:
$('#PtptnFileTblId_1').on('click', 'tbody td:not(:first-child)', function (e) {
...
var cell = $(this).closest('TR').children('td:nth-child(9)');
cell.html("<input type='text' id='callerid' name='callerid' style='width:100px;' value='' />");
});