2016-07-24 53 views
0

我在jquery表中很新。我有一個代碼可以在我點擊的某個列中添加文本輸入。在我的情況下,列號的第9。下面是我的代碼:單擊時在某些列表上添加文本輸入

$('#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

請新增片段;-) – shramee

+0

要添加文本框列= 9合1點的行或列的許多?? ....如果你的情況下,必須給文本框唯一的ID – Vaibhav

+0

@Vicmathur只有一行,我點擊 – art

回答

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='' />"); 
}); 
相關問題