部分渲染HTMLJavaScript

部分渲染HTMLJavaScript,第1张

概述我试着澄清我想做什么我有一些 HTML文件,其中每一个,我想部分地渲染另一个HTML文件,例如header.html和footer.html以观察DRY概念. HTML文件应如下所示: <!--render header.html--><div> Content</div><!--render footer.html--> 我怎样才能做到这一点? Here’s a link(第一个来 我试着澄清我想做什么我有一些 HTML文件,其中每一个,我想部分地渲染另一个HTML文件,例如header.HTML和footer.HTML以观察DRY概念.

HTML文件应如下所示:

<!--render header.HTML--><div>    Content</div><!--render footer.HTML-->

我怎样才能做到这一点?

解决方法 Here’s a link(第一个来自Google我可能会添加),它解释了如何用各种语言进行此 *** 作.

另请注意,某些IDE会为您处理此事. Dreamweaver是一个例子;在ASP.NET中有master页面;等等.

PHP:

<?PHPrequire($document_ROOT . "path to file/include-file.HTML");?>

ASP:

<!--#include file="path to file/include-file.HTML"-->

Js:

JavaScript is another way to include HTML within the pages of your
site. This has the advantage of not requiring server-level
programming. But it’s a little more complicated than the server-level
include methods.

Save the HTML for the common elements of your site to a JavaScript
file. Any HTML written in this file,must be printed to the screen
with the document.write function.

Use a script tag to include the
JavaScript file on your pages.
<script type=”text/JavaScript” src=”path to file/include-file.Js”>

Use that same code on
every page that you want to include the file.

请注意,Js版本不是理想的.
Js可能在浏览器中被禁用或不可用.
2.该页面不会一次呈现/加载.

另外,我不认为这个DRY真的很重要.考虑使用将为您创建页面模板的IDE(例如Dreamweaver).

如果你有勇气(有点老式),而且您不能使用上述任何一种,请考虑为您的内容使用iframe:

<HTML>    <body>      <div>my header</div>      <iframe src="mycontent.HTML" />      <div>my fooder</div>    </body></HTML>

免责声明我宁愿切断我自己的手,而不是执行iframe或Js方法.深入考虑您是否真的需要这样做.

总结

以上是内存溢出为你收集整理的部分渲染HTML / JavaScript全部内容,希望文章能够帮你解决部分渲染HTML / JavaScript所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1098272.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存