反转HTML表的行而不反转顶部
reversing rows of an HTML table without reversing the top
我有一个表,基本上是这样的:
a1 a2 a3
b1 b2 b3
c1 c2 c3
我想把它倒过来,使它看起来像这个
c1 c2 c3
b1 b2 b3
a1 a2 a3
每当按下"点击我"按钮时,
<table class='standardtable'>
<tr>
<th>Event</th>
<th>Group</th>
<th>Course</th>
<th>Due Date</th>
<th>Due In/<span class='red'>Late By</span></th>
<button onclick="myFunction()">Click me</button>
</tr>
<td id='others'>
<?php
echo $html->tableCells($evalUpcoming);
?>
<?php if (empty($evalUpcoming)):?>
<tr><td colspan="5" align="center"><b> No peer evaluations due at this time </b></td></tr>
<?php endif; ?>
</td>
显然,第一行是标题,其他行是内容。我试着用td分隔第一行和另一行,但似乎不起作用:
<table class='standardtable'>
<tr>
<th>Event</th>
<th>Group</th>
<th>Course</th>
<th>Due Date</th>
<th>Due In/<span class='red'>Late By</span></th>
<button onclick="myFunction()">Click me</button>
</tr>
<td id='others'>
<?php
echo $html->tableCells($evalUpcoming);
?>
<?php if (empty($evalUpcoming)):?>
<tr><td colspan="5" align="center"><b> No peer evaluations due at this time </b></td></tr>
<?php endif; ?>
</td>
<script>
function myFunction(){
var table = document.getElementById('others');
for (var i = 0; i < table.length; i++) {
var rows = table[i].rows;
for (var j = 0; j < rows.length; j++) {
rows[j].parentNode.insertBefore(rows[rows.length-1], rows[j]);
}
}
}
</script>
有人能告诉我如何在不倒上排的情况下把这张桌子倒过来吗?
这样构建表:
<table class='standardtable'>
<thead> <!-- use thead to separate headercontent -->
<tr>
<th>Event</th>
<th>Group</th>
<th>Course</th>
<th>Due Date</th>
<th>Due In/<span class='red'>Late By</span></th>
<button onclick="myFunction()">Click me</button>
</tr>
</thead>
<tbody> <!-- use tbody to separate tablecontent-->
<?php
echo $html->tableCells($evalUpcoming);
?>
<?php if (empty($evalUpcoming)):?>
<tr><td colspan="5" align="center"><b> No peer evaluations due at this time </b></td></tr>
<?php endif; ?>
</tbody>
我想我的解决方案有点晚了,但是的,如果你用thead和tbody来分隔元素,那么你就可以得到排序的分隔,这样只有tbody的子元素才会被排序。
<table class='standardtable'>
<thead>
<tr>
<th>Event</th>
<th><button onclick="myFunction()">Click me</button></th>
</tr>
</thead>
<tbody id="table-body">
<tr>
<td>a</td>
<td></td>
</tr>
<tr>
<td>b</td>
<td></td>
</tr>
<tr>
<td>c</td>
<td></td>
</tr>
</tbody>
</table>
下面是它的一个示例实现,它使用了一种简单的方法来反转表体元素jsfiddle
相关文章:
- HTML 表单目标到顶部框架
- 滚动然后修复到 html 中的顶部标题
- HTML导航在屏幕底部,并粘贴到顶部
- 将html页面刷新到页面顶部
- 如何让我的导航栏位于每个HTML页面的顶部(避免复制相同的代码)
- Chrome扩展-在全屏视频顶部显示自定义通知/弹出窗口(HTML元素)
- 我如何使用滚动顶部()获取HTML文档的位置
- 如何创建 HTML 文本框,该文本框顶部有一个水平菜单选项卡可供选择
- 如何防止作用在 html 锚点上的 JS 插件跳到顶部
- 在锚标记顶部显示交互式 Html 元素
- 在 HTML 中向下滚动时将导航栏移动到顶部
- 我将如何在 HTML/CSS 中始终将固定导航保持在顶部
- 允许 Raphael/SVG 元素事件通过顶部分层的 HTML 触发
- 在HTML和Javascript中的图像顶部“绘制”
- 如何使用 JavaScript 强制 HTML 页面在所有移动浏览器中滚动到顶部
- 代码在以下情况下不起作用:<!DOCTYPE html>顶部
- d3-在svg元素的顶部呈现一个html表
- 反转HTML表的行而不反转顶部
- HTML窗口刷新页面顶部
- 在HTML页面顶部形成奇数空格