如何在html中重复代码而不必反复编写相同的代码 [英] How to repeat a code in html without writing the same code again and again
问题描述
我希望在给定的页面上多次显示给定的代码片段,但我希望尽量减少在任何地方重复的冗余代码(简单的复制/粘贴)。好吧,我听说有人使用Javascript或JQuery来存储给定的代码片段,比如HTML或CSS,而不是使用一些简单的div渲染或<! - data - >
在他们希望代码出现的任何地方标记多次,我不知道如何使用它在脚本或html中存储信息,然后使用单个div或注释呈现多个位置。
Well I wish to show a given piece of code multiple times on a given page but I wish to minimize the redundant code being repeated everywhere (simple copy/paste) . Well I heard of people using Javascript or JQuery to store the given piece of code say HTML or CSS and than they use some simple div renders or the <!--data-->
tag multiple number of times in wherever place they want the code to appear, which I have no idea how to use that is store a info in the scripts or html and then render it multiple number of places with a single div or comment.
任何人都可以举例说明如何做到这一点。关于这些技巧的更多信息将非常有用。
Can anyone illustrate how to do this with an example. A bit more info on such tricks will be very resourceful.
推荐答案
看看服务器端包含
在您的网页中包含以下内容:
Include it like this in your page :
<?php include ('content.html'); ?>
这篇关于如何在html中重复代码而不必反复编写相同的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!