我有一個表格,其中所有的單元格都是INPUT標籤。我有一個函數,它查找第一個輸入單元格,並用它的值替換它。所以這樣的:jQuery參考HTML表格中的第一列
<tr id="row_0" class="datarow">
<td><input class="tabcell" value="Injuries"></td>
<td><input class="tabcell" value="01"></td>
變成這樣:
<tr id="row_0" class="datarow">
<td>Injuries</td>
<td><input class="tabcell" value="01"></td>
下面是函數的第一部分:
function setRowLabels() {
var row = [];
$('.dataRow').each(function(i) {
row.push($('td input:eq(0)', this).val() + ' -> ');
$('td input:eq(0)', this).replaceWith($('td input:eq(0)', this).val());
$('td input:gt(0)', this).each(function(e) {
etcetera
但是,當重新加載頁面時,第一列是不是輸入型,所以它會將第二列更改爲文本!
我可以告訴它只更改第一列,不管類型是什麼?我試過
$('td:eq(0)', this).replaceWith($('td:eq(0)', this).val());
但它不起作用。
任何建議表示讚賞!
當我第一次看到你的迴應時,我以爲你已經輸入了我第一次嘗試的東西。重讀後,我看到你改變了 'td input:eq(0)' to'td:eq(0)input'
它工作! 謝謝! – Vic 2010-05-27 19:33:59
不客氣。很高興工作! – user113716 2010-05-27 19:39:36