我在html
中創建了兩個表.. 如何通過複選框選擇行來將行從一個表移動到另一個表? 任何人都可以給我一個示例JS來做到這一點。由於html表值交換
Q
html表值交換
2
A
回答
1
試試這個:
<script type="text/javascript">
function moveIt() {
$('#table-1 input[type=checkbox]:checked').each(function() {
var tr = $(this).parents('tr').get(0);
$('#table-2').append($(tr));
});
}
</script>
<table border="1" id="table-1">
<tr>
<td><input type="checkbox"></td>
<td>First</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>Second</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>Third</td>
</tr>
</table>
<table border="1" id="table-2">
</table>
<input type="button" onclick="moveIt()" value="move selected lines from table-1 to table-2" />
不要忘記,包括jQuery的。
0
+0
回答你這很好,除非它不能在IE ... – Teemu 2012-04-19 08:37:44
1
簡單的方法可以做到這一點使用jQuery。像這樣的東西應該可以完成這項工作。
$(function() {
// Bind button
$('#moveRows').click(moveSelectedRows);
// Select All-button
$('#selectAll').click(function() {
$('#table1 input[type="checkbox"]').prop("checked", true);
});
});
function moveSelectedRows() {
$('#table1 input[type="checkbox"]:checked').each(function() {
// Remove from #table1 and append to #table2
$('#table2').append($(this).closest('tr').remove());
// Remove the checkbox itself
$(this).remove();
});
}
HTML
<a href="#" id="selectAll">Select All</a>
<table id="table1">
<tr>
<td>Foo1 <input type="checkbox" /></td>
</tr>
<tr>
<td>Bar2 <input type="checkbox" /></td>
</tr>
</table>
<table id="table2">
<tr>
<th>Selected rows</th>
</tr>
</table>
<a id="moveRows" href="#">Move rows</a>
相關問題
- 1. HTML表單提交空值
- 2. 交換機註冊表值
- 3. 交換2 HTML表格元素
- 4. HTML表單提交的默認值
- 5. 交換價值
- 6. 交換價值
- 7. 交換值
- 8. 交換行值
- 9. 交換價值
- 10. SQL - 交換/交換字段值
- 11. sql表中第2行的交換值
- 12. 交換數據庫表的值
- 13. 使用LINQ交換列表值
- 14. 交換SQL Server表中的兩個值
- 15. Html表單提交
- 16. 提交HTML表單
- 17. html表格提交
- 18. HTML表單提交
- 19. 交換錶行
- 20. [SED/AWK]交換值
- 21. SQL:交換列值
- 22. 交換宏的值
- 23. 交換指針值
- 24. 當提交HTML表單時,將所有$ _POST值轉換爲整數?
- 25. 交換奇鏈表
- 26. SQL Server表交換
- 27. Oracle:交換表名
- 28. PHP/HTML表單提交
- 29. html表單提交按鈕
- 30. 自動提交HTML表單
你可以在這裏給你的代碼,所以我們也可以在代碼 – 2012-04-19 07:32:19