将 HTML 头放在另一个文件中

2022-01-11 00:00:00 header include javascript html

有没有办法将所有 meta taglink relscript src 包含在一个文件中,然后要求该文件?

Is there a way to include all the meta tag, link rel and script src includes in one file, and then require that file?

我问的原因是因为我有 10-15 行要复制到每个文件中,并认为可能有另一种方法.

The reason I ask is because I have like 10-15 lines that i am copying into every file and figured there might be another way.

我将所有内容都放在一个文件中,并尝试了 Jquery 加载功能,但无济于事.

I put everything in one file and tried the Jquery load function, but to no avail.

谢谢

推荐答案

像这样创建一个 head.html 文件:

Create a head.html file like this:

<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!-- JS -->
<script type="text/javascript" src="js/lib/jquery-1.11.min.js" ></script>
<script type="text/javascript" src="js/lib/angular.min.js"></script>
<title>Your application</title>

现在在您的 HTML 页面中包含 head.html,如下所示:

Now include head.html in your HTML pages like this:

<head>
   <script type="text/javascript" src="js/lib/jquery-1.11.1.min.js" ></script>
   <script>
       $(function(){ $("head").load("head.html") });
   </script>
</head>

相关文章