Fe-interview: [html] 第442天 开发静态页面时,不依赖node相关的工具,如何提取出公共部分并引入?

Created on 30 Jun 2020  ·  2Comments  ·  Source: haizlin/fe-interview

第442天 开发静态页面时,不依赖node相关的工具,如何提取出公共部分并引入?

3+1官网

我也要出题

html

All 2 comments

比如我现在有一个index.html,如果要在其中html中引入html的话,我们假设该组件为modal.html,我们现在可以写一个最简单的html文件展示一下:

<html>
  <head>
    <style></style>
  <head>
  <body>
    <div>
      <include src="./modal.html"></include>
    </div>
  </body>
</html>

这样一段html代码就被引入了,当然我们可以在里面加入JS代码,它的编译顺序就是DOM节点顺序顺次下来,JS运行时要注意一下时序的问题。
以上,css和js组件可以直接用script标签引入,html组件可以用include标签引入。

利用iframe,感觉有点取巧,勉强也算吧

// test-include.html
<html>
<head>
</head>
<body>
    test
    <iframe marginwidth=0 marginheight=0 width="100%" height=200 src="./test-include2.html" frameborder="no"></iframe>
</body>
</html>

// test-include2.html
<html>
<head>
</head>
<body>
    test2
</body>
</html>
Was this page helpful?
0 / 5 - 0 ratings