在同一页上多次重复表格
我有一个相当复杂的html表,其中包含大量PHP、CSS等,它包含大约200行代码。我需要在网页上的三个不同区域重现该表。第二次和第三次复制表的最佳方法是什么,这样我就不必每次都复制并粘贴 200 行代码?当然,必须有一个最佳实践来做到这一点。
I have a fairly complicated html table containing lots of PHP, CSS etc., and it comprises about 200 lines of code. I need to reproduce the table in three different areas on my webpage. What is the best approach to replicating the table the 2nd and 3rd time so that I don't have to copy and paste the 200 lines of code each time? Surely there must be a best-practice for doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以只使用包含文件,然后在需要表格的每个页面上放置对包含文件的引用。
可以在此处找到来自 w3schools 的更多信息:
http://www.w3schools.com/php/php_includes.asp
You can just use include files, then put a reference to the include file on each page where you want the table.
And more info from w3schools can be found here:
http://www.w3schools.com/php/php_includes.asp
你在使用 jQuery 吗?数据源自哪里?它是硬编码的还是在数据库中?我认为你是正确的,你不应该向用静态 HTML 编码的视图(首先)添加甚至 200 行的表。
请提供您的问题的详细背景以及您想要完成的任务,我会尽力帮助您。
Are you using jQuery? Where does the data originate? Is it hard coded or in a database? You are correct in my opinion, you should never be adding even a 200 row table to your view (in the first place) that is coded in static HTML.
Please provide some detailed context for your problem and what you are trying to accomplish and I will try and help you out.
如果您要从数据库查询信息,这里有一个使用 PHP 的解决方案。这将为从数据库返回的每个结果创建一个新行。我假设您使用数据库来处理 200 条不同的信息?
希望这对您有所帮助:)
编辑:只需重新阅读问题,就跳船了一点恐怕(抱歉)我建议上面的海报和他的包含方法:)
Here is a solution using PHP if you are quering your information from a database. This will make a new row for each result that is returned from your DB. I presume that with 200 different bits of information you are using a database for that?
Hope this helps you out somehow :)
EDIT : Just re-read the question, jumped the boat a bit there Im afraid (apologies) I suggest the poster above and his includes method :)
在桌子周围放置一个带有 id 的 div 包装。然后将空的 div 放在需要的其他位置:
Put a div wrapper around the table with an id. then put empty divs in the other spots it needs to go then: