我在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