简体   繁体   English

为什么我的html导入标签不起作用?

[英]Why does my html import tag not work?

I have been looking at code reusability (for example) and have been experimenting with HTML import tags. 我一直在研究代码的可重用性(例如),并且一直在尝试HTML导入标签。 I want to auto include my bootstrap code in every webpage and would like to do it with one line of code as opposed to multiple. 我想在每个网页中自动包含引导代码,并希望使用一行代码而不是多行代码来完成。

After doing some research online, the answer seemed to be to use the tag, most namely the following format: 在网上进行了一些研究之后,答案似乎是使用标签,最主要是以下格式:

<head>
    <import rel="import" href="includes/bootstrap.html">
</head>

My bootstrap.html file is just some normal bootstrap links as follows: 我的bootstrap.html文件只是一些常规的bootstrap链接,如下所示:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

I'm simply trying to avoid importing the same three lines across all my pages. 我只是想避免在所有页面上导入相同的三行。 However, my browser (Chrome) does not seem to implement include in any way, even when I use for reasons other than Bootstrap. 但是,即使我出于Bootstrap以外的原因使用浏览器(Chrome),也似乎没有以任何方式实现包含。

How should I properly include my bootstrap files across the head of all my pages? 我应该如何在所有页面的头部适当地包含引导文件?

Alex 亚历克斯

How about creating a header file 'header.php' with the links like so, 如何使用这样的链接创建头文件“ header.php”,

<head>
<title>Your Title</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
</head>

And when you write your code just include the header.php part. 当您编写代码时,只需包含header.php部分。

<html>
<? include ("header.php");?>
</html>

Change import tag to link tag 将导入标签更改为链接标签

<head>
    <link rel="import" href="includes/bootstrap.html">
</head>

Refer this 推荐这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM