我正在循環一組動態表格行,我試圖捕獲每個表格行中使用jquery的cell2的值,但它每次都返回cell2 row1的值,甚至雖然它每次都能識別單元格1的正確行值,但有誰能告訴我我錯了嗎?見下面的示例代碼。爲jQuery中的每個表格計算文本框
感謝您收到的任何幫助。
//html
<table class=plantTable>
<tr>
<td><input type=text value=0 class=cell1></td>
<td><input type=text value=0 class=cell2></td>
<td><input type=text value=0 class=cell3></td>
</tr>
<tr>
<td><input type=text value=0 class=cell1></td>
<td><input type=text value=0 class=cell2></td>
<td><input type=text value=0 class=cell3></td>
</tr>
<tr>
<td><input type=text value=0 class=cell1></td>
<td><input type=text value=0 class=cell2></td>
<td><input type=text value=0 class=cell3></td>
</tr>
</table>
//jquery
tr = $(".plantTable tr").length;
$(tr).each(function() {
$(this).find($(".cell1").blur(function() {
cell1val = parseInt($(this).val());
cell2val = parseInt($(".cell2").val()); //Returns the value of cell2 in the first row only?
}));
'tr'等於一個整數,'TR = $(「TR plantTable」)長度;' – 2013-02-14 16:01:35
HTTP: //codepen.io/anon/pen/GCdpA – Shanimal 2013-02-14 16:18:30