首页 > 解决方案 > 将 HTML 导入 HTML

问题描述

我需要将 A.html 和 B.html 和 C.html 导入 Index.html

我尝试的方式.....它可以工作,但不知道只有一个是正常的,其他不与他们的css链接


下面是我的 index.html

它可以工作,但只有 D.html 链接它的 css。其他人的 css 布局看起来不正确。

<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/A.css">
<link rel="stylesheet" href="css/B.css">
<link rel="stylesheet" href="css/C.css">
<link rel="stylesheet" href="css/D.css">


<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" defer></script>
<section ng-app="">
  <div ng-include="'section/A.html'"></div>
  <div ng-include="'section/B.html'"></div>
  <div ng-include="'section/C.html'"></div>
  <div ng-include="'section/D.html'"></div>
</section>

标签: jqueryhtmlangularjsajax

解决方案


这是我为帮助您解决问题而做的一个 codepen 项目: https ://codepen.io/ideaguy3d/project/editor/AdzPdm

我刚刚添加了一个角度应用程序并将 ng-app 指向它:

应用程序.js:

angular.module('myApp', []);

索引.html:

```

   <section ng-app="myApp">

        <div ng-include="'section/A.html'"></div>
        <div ng-include="'B.html'"></div>

    </section>

```

确保您的项目中也有一个名为“section”的文件夹。


推荐阅读