简体   繁体   English

我应该用吗? <table> 要么 <ul> ?

[英]Should I use <table> or <ul>?

I have to render dynamic data using javascript which should be displayed as n rows, m columns. 我必须使用javascript渲染动态数据,javascript应显示为n行,m列。 I have heard of ill-effects of using tables but cannot justify on my own as to why I should/should-not use tables. 我听说过使用表格的不良影响,但我不能证明为什么我应该/不应该使用表格。 Can you reason the best practice in choosing the alternative for the requirement. 您能否选择最佳实践来选择替代方案。 I at all <ul> is the alternative, how do I manage to make it look like a table? 我完全可以选择<ul> ,如何让它看起来像桌子?

If I use tables, I cannot animate table rows. 如果我使用表格,我无法为表格行设置动画。 Keeping this consideration, please suggest the alternative. 考虑到这一点,请提出替代方案。

You should not use tables for layout . 您不应该使用表格进行布局 It's perfectly reasonable to use tables for tabular data. 将表用于表格数据是完全合理的。 If you have "n rows" and "m columns", that sounds an awful lot like tabular data and it would be appropriate to use a <table> . 如果你有“n行”和“m列”,这听起来很像表格数据,并且使用<table>是合适的。

As far as "animating" table rows, if by that you mean dynamically adding and removing rows from a table using javascript, that is supported. 至于“动画”表行,如果你的意思是使用javascript动态添加和删除表中的行,则支持。 See the DOM Reference for table methods . 有关表方法,请参阅DOM参考 It supports operations such as insertRow() and deleteRow() . 它支持insertRow()deleteRow()

Tables are sementically used for the tabular data, it is bad when you use them for layout purposes. 表格用于表格数据,当您将它们用于布局目的时,表格很糟糕。 In your case, you can use the tables since you want to show some data and i wonder how you can not animate table rows? 在您的情况下,您可以使用表格,因为您想要显示一些数据,我想知道如何不能为表格行设置动画? Thanks 谢谢

See W3C's : Tables in HTML Documents 请参阅W3CHTML文档中的表

This is a very common dilemma in the Web developers head. 这是Web开发人员头脑中非常常见的两难问题。 Actually using table sometimes make it easy to create web pages but makes it really difficult when you try to modify them or edit them. 实际上使用表格有时可以轻松创建网页,但在尝试修改或编辑网页时却非常困难。 Tables should only be used to create tabular data like data-grids or representing lists in a tabular layout. 表只应用于创建表格数据,如数据网格或表格列表中的列表。 Using the right markup for the right layout makes a lot of semantic sense for the webpage and makes it much more readable. 对正确的布局使用正确的标记可以为网页提供很多语义感,并使其更具可读性。 You can check the following links to learn more about the significance of Semantic HTML. 您可以查看以下链接,以了解有关语义HTML的重要性的更多信息。

http://www.communitymx.com/content/article.cfm?cid=0BEA6 http://www.thefutureoftheweb.com/blog/writing-semantic-html http://www.communitymx.com/content/article.cfm?cid=0BEA6 http://www.thefutureoftheweb.com/blog/writing-semantic-html

The first sentence of your question describes a table so you should render it as a table. 您的问题的第一句描述了一个表,因此您应该将其呈现为表格。

Is animating the rows really necessary? 动画行真的很有必要吗?

Tables are the right choice for the situation. 桌子是这种情况的正确选择。

If you use jQuery, you can animate an li or a tr or anything else. 如果你使用jQuery,你可以动画litr或其他任何东西。

Here's an example of deleting a row with jQuery: 这是使用jQuery删除行的示例:

close_timeout = setTimeout(function() { 
    $("tr#row_"+id).css("background","red");
    $("tr#row_"+id).animate({ opacity: 'hide' }, "slow");           
}, 600);
$("tr#row_"+id).remove();

This changes the background to red, hides the tr , and then removes it from the DOM. 这会将背景更改为红色,隐藏tr ,然后将其从DOM中删除。

I hope this helps. 我希望这有帮助。

It's data. 这是数据。 Use tables. 使用表格。

Try this jQuery plugin for formatting your table: 试试这个jQuery插件来格式化你的表格:

http://tablesorter.com/docs/ http://tablesorter.com/docs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM