2017-01-01 59 views
1

這裏是我的javascript代碼:

$("#gridProcessDetail tbody").on('click', 'tr', function() { 
$(this).context.cells.each(function (ind) { 
    var txt = $(this).html(); 
    }); 
} 

$(this).context.cells返回兩個細胞,但它說:

html is not is not a function at HTMLTableRowElement.<anonymous> (Invoice:472) 
    at HTMLTableSectionElement.dispatch (jquery-1.11.3.min.js:4) 
    at HTMLTableSectionElement.r.handle (jquery-1.11.3.min.js:4) 
+0

你爲什麼不使用'$( 'TD',這一點)。每個()'?沒有明智的理由,您正在將jQuery API與DOM API混合使用。 – undefined

回答

1

context返回一個DOM節點(在1.10.0中不推薦使用),並且jQuery .each()函數試圖迭代DOM節點。

這將是更好的代碼更改爲:

$("#gridProcessDetail tbody").on('click', 'tr', function() { 
$(this).children().each(function (ind) { 
    var txt = $(this).html(); 
    }); 
});