本文介绍了我怎样才能简单地使我的HTML表格'动态'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想知道是否有简单的方法使表格动态化,也就是说,允许观众通过点击列标题来对其进行排序,或者通过输入简单的规则来过滤记录。 我不太了解HTML。我使用Perl进行编码,只生成HTML(实际上,Multimarkdown转换为HTML)以很好地输出一些数据。我提到这一点,因为我确信有各种方法可以创建漂亮的动态表格,但是我真的很想找一个简单的表格。 简单的方式是使用已支持这些功能的工具箱/库。 (快速谷歌搜索排序的JavaScript表出现了表格从JavaScript Toolbox中排序/过滤,使用JavaScript对HTML表进行排序(更多示例)和 jQuery插件:Tablesorter 2.0 。) AJAX是一款机制,可用于动态获取数据 - 但是,如果所有数据已经​​存在于表中和/或表不需要分页,那么它是过度的。这两种方法都要求启用客户端JavaScript。 (非客户端的替代方案是回传并让服务器完成这项工作并生成新的HTML,但这是Web一点 - 哦: - ) CSS(层叠样式表)仅用于应用样式,如颜色,背景图像,字体或边框等(CSS选择器可以基于通常在HTML元素 class attribute 中提供的CSS类来工作)文档只是简单地说明一些预定义的CSS类名是动态添加 - 通过JavaScript - 因此可以轻松地选择样式 - 例如,将已分类的列石灰转为绿色)。但是,CSS本身无法控制排序或过滤。 Daxim建议斯图尔特兰格里奇的排序表达式在下面的SO问题中讨论: 如何做客户端排序使用查询字符串中的超链接与表头关联使用Perl?(如果此编辑有用,请上传daxim: - ) 快乐编码。 I'm writing Multimarkdown from Perl to create an HTML table.I wonder if there's a simple way to make the table dynamic , that is, allow the viewer sort it by clicking on a column header, or even filter records by entering a simple rule.I do not really know HTML. I'm coding in Perl and only generate HTML (actually, Multimarkdown converted to HTML) to nicely output some data. I mention this since I'm sure there are various ways to create beautiful, dynamic tables, but I'm really looking for a simple one. 解决方案 The simple way is to use a toolkit/library that already supports such features.(A quick google search for "sorting javascript table" turned up Table with sorting/filtering from JavaScript Toolbox, Sorting HTML Tables using JavaScript (more of example) and jQuery plugin: Tablesorter 2.0.)AJAX is one mechanism that can be used to fetch data dynamically -- however, if all the data is already present in the table and/or the table doesn't need paging, then it's overkill. Both of these methods require that client-side JavaScript is enabled. (The non-client side alternative would be to post-back and have the server do the work and generate new HTML. But that's so Web one-point-oh :-)CSS (Cascading Style Sheets) is just for applying styles such as colors, background image, fonts or borders, etc (CSS selectors can work based on CSS classes which are often supplied in the HTML element class attribute. The documentation is simply stating that some pre-defined CSS class names are dynamically added -- by the JavaScript -- and thus can be "selected" upon easily for styling - for example, turning the sorted column lime green). CSS itself, however, can't control the sorting or filtering.Daxim suggested Stuart Langridge's sorttable which is discussed in the following SO question:how to do client side sorting using querystring in hyperlink associated with the table header using Perl? (Go upvote daxim there if this edit was useful :-)Happy coding. 这篇关于我怎样才能简单地使我的HTML表格'动态'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 06:33
查看更多