有一個鏈接被點擊時,增加了一個新行的表:添加行的一部分,作爲新行表
<table>
<thead>
<tr>
<th scope="col">col1</th>
<th scope="col">col2</th>
<th scope="col">col3</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name="col1" id="col1"></td>
<td><input name="col2" id="col2"></td>
<td>
<select name="col3" id="col3">
<option value="">Please select</option>
<option value="1">select1</option>
<option value="2">select1</option>
<option value="3">select1</option>
</select>
</td>
</tr>
</tbody>
</table>
<a href="#" id="addLink">+</a>
鏈接被點擊的時候,我想添加一個新行但沒有第三列到表的末尾。所以我用jQuery來做到這一點:
$(document).ready(function(){
$('#addLink').click(function(){
addTableRow($("table"));
return false;
}); // end click
function addTableRow(table)
{
// get the first row in the table
var $tr = $(table).find("tbody tr:first").html();
$($tr).remove('td:last'); // remove the last column
$('tbody').append("<tr>");
$(table).find('tbody tr:last').append($tr);
};
}); // end ready
然而,這部分是不刪除第3列:
$($tr).remove('td:last'); // remove the last column
是有什麼辦法可以追加一個新行只是第2列?
感謝提前:)
刪除( 'TD:EQ(3)') – max4ever
@ max4ever這個人是不工作... –
你想是這樣的http://jsfiddle.net/j08691/ dktqs /? – j08691