Html 如何在表格中使用“sortable”和“sorted”属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22376476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use the "sortable" and "sorted" attributes in tables?
提问by Sipo
I recently saw in the W3Schoolshtml tags reference two attributes I don't quite understand. The first is the <table sortable="sortable">
attribute, and the second is <th sorted="sorted">
attribute.
我最近在W3Schoolshtml 标签中看到引用了两个我不太明白的属性。第一个是<table sortable="sortable">
属性,第二个是<th sorted="sorted">
属性。
According to W3Schools, the sortable
attribute description is:
根据W3Schools,sortable
属性描述是:
Specifies that the table should be sortable
指定表格应该是可排序的
And the description for the sorted
attribute is:
该sorted
属性的描述是:
Defines the sort direction of a column
定义列的排序方向
And the values the sorted
attribute accept are:
sorted
属性接受的值是:
reversed
number
reversed number
numberreversed
反转
号码
反转号码
号码反转
I tried to follow the W3C documentation hereabout how to use those attributes but it doesn't works for me.
我试图按照 W3C 文档here了解如何使用这些属性,但它对我不起作用。
I would be very thankful for an answer. Thank you.
我将非常感谢您的回答。谢谢你。
回答by X. Liu
In 2016, the table sorting model (including "sortable" and "sorted" attributes) was completely removed from HTML5.1 draft, due to lack of implementations.
2016 年,由于缺乏实现,表格排序模型(包括“sortable”和“sorted”属性)从 HTML5.1 草案中完全删除。
Reference: https://github.com/w3c/html/issues/56
回答by Pierre Rust
The W3C document your are referring to is a draft for HTML 5.1, which is scheduled for publication in 2016 and not implemented in any browser today AFAIK (hey, HTML 5 is not yet fully implemented and targets feature freeze in june 2014).
您所指的 W3C 文档是HTML 5.1的草案,计划于 2016 年发布,目前尚未在任何浏览器中实现 AFAIK(嘿,HTML 5 尚未完全实现,目标功能在 2014 年 6 月冻结)。
Now, if you need sortable table, there are plenty javascript-based libraries out there that can do that.
现在,如果您需要可排序的表,有很多基于 javascript 的库可以做到这一点。