我想在同一行單擊按鈕時獲取colB
中的文本框的值。 但是,我的選擇器沒有到達那裏。此外,它必須在IE8中工作。如何在此表佈局中查找文本框的值?
<table>
<thead>
<tr>
<th> </th>
<th>colA</th>
<th>colB</th>
</tr>
</thead>
<tbody>
<tr>
<td> <a class=btn class=foo>foo</a>
</td>
<td>
<input type=text value=1 />
</td>
<td>
<input type=text value=2 />
</td>
</tr>
<tr>
<td> <a class=btn class=foo>foo</a>
</td>
<td>
<input type=text value=3 />
</td>
<td>
<input type=text value=4 />
</td>
</tr>
</tbody>
</table>
$('.foo').on('click', function (item, evt) {
var foo = $(evt.target);
var tr = btn.parent().parent();
var col3 = tr.children(':eq(2)');
var txt = col3.find('input');
alert(txt.val());
});
樣本代碼在匆忙中鍵入。由於我在KO.js中使用了click,因此我使用'evt.currentTarget'而不是'this'。 –