6

原谅我的无知,因为这似乎是我现在应该知道的事情。

我知道我可以制作一个样式表,允许我在使用 CSS 的多个页面中对我的 CSS 进行更改。我也知道您可以制作一个外部 javascript 文件,其中可能包含您想要重用的函数。但是假设我有想要在多个页面上复制的纯 HTML 内容(假设是一堆按钮或链接)。在这方面有什么类似于样式表的吗?这将允许您一次更新按钮/链接。

4

8 回答 8

3

Try server-side includes.

The most frequent use of SSI is to include the contents of one or more files into a web page on a web server. For example, a web page containing a daily quote could include the quote by placing the following code into the file of the web page:

You could also use PHP, if your host allows it. Just change the name of the page from .html to .php and reference the header:

<?php include "header.php" ?>

Both of these require you to change the file's extension, so you might also want to use mod_rewrite to let users still access it via the .html name. Again, if your host supports it.

于 2010-06-22T19:05:35.330 回答
1

取决于... 我知道 Dreamweaver 对模板有一些相当高级的支持。您可以深入研究 WYSIWYG HTML 编辑器的手册,并熟悉它如何帮助您处理可重复的内容项。否则,正如 Simon 暗示的那样,您应该考虑学习一些服务器端技术(脚本语言如 PHP 是一个简单的选择),编写可重复的 HTML 并让脚本随时随地输出。祝你好运!

于 2010-06-22T19:10:36.143 回答
1

The question isn't that stupid, as there in fact is nothing native in HTML to do this.

If supported by your server, Server Side Includes are your best option. If you have PHP, you can also do a <?php include "footer.html"; ?>

All other server side languages have a similar construct.

于 2010-06-22T19:08:44.077 回答
0

You can try using the CSS content property, but the content is inserted after/before the target. http://www.w3schools.com/Css/pr_gen_content.asp

EDIT

You can also try storing your content in XML documents and using JavaScript to load the XML sheets. Each sheet can store your button content, input content, etc. All you have to do is parse the XML and render the content as HTML elements.

于 2010-06-22T19:05:15.757 回答
0

It seems you're not using some server side technology like ASP.NET which has user controls on which you could place those.

An alternative would be to use Server Side Includes like:

<!--#include virtual="header.html"-->

Grz, Kris.

于 2010-06-22T19:06:24.580 回答
0

除非您不关心 SEO,否则我建议您不要为此目的使用 javascript。

这是可能的,但这种技术可能会阻止搜索引擎正确索引您的网站。

于 2010-06-25T20:41:19.280 回答
0

如果 SSI 或 PHP 均不可用,则只能使用 javascript 进行操作:将页面加载到隐藏的 IFRAME 中,然后抓取它(使用 innerHTML) - 并将其移动到您需要的位置。

于 2010-06-22T21:04:46.543 回答
0

虽然我认为 SSI 似乎是最好的主意,但如果记忆对我有用,那么如果您使用 IIS,您将不得不调整服务器上的一些设置才能使用 html 文件扩展名获取 SSI。

虽然 SimpleCoder 的想法似乎不是最好的想法,但它是一个有趣的想法。基于这个想法,也许 json 数据而不是 xml 是最好的。我会玩这个只是为了好玩。

于 2010-06-22T20:33:57.030 回答