Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
在HTML页面中引入外部HTML文件的解决方案_创想鸟

在HTML页面中引入外部HTML文件的解决方案

在普通的静态html开发过程中,没必要用框架,只想用最基本的方式写几个静态页面出来,但是html中没有include语法,每个页面的公共部分都要手动复制粘贴一次,实在不科学……

在HTML页面中引入外部HTML文件的解决方案

在网上看了有如下的解决方案:   ( 推荐学习:html教程 )

方案一:将html文件转为js文件,然后在页面加载的时候将其加载进来执行渲染

方案二:使用iframe标签进行引用

立即学习“前端免费学习笔记(深入)”;

方案三:使用gulp插件gulp-html-import

本人推荐使用第三种方案,使用起来也很方便,下面介绍使用步骤:

1、npm install gulp -D

2、npm install gulp-html-import -D

3、目录结构:

    |    -- html-import    |   |    |   -- components    |   |    |    |   |    -- header.html    |   |    |    |   |    -- footer.html    |   |    |   -- index.html    |   -- gulpfile.js

4、gulpfile.js

   var gulp = require('gulp');   var htmlImport = require('gulp-html-import');      gulp.task('import', function () {       gulp.src('./*.html')          .pipe(htmlImport('./components/'))          .pipe(gulp.dest('dist'));    })

5、index.html

        Gulp-html-import Example    @import "header.html"    

Hello World

@import "footer.html"# 使用标签@import "XXX.html"引入公共页面

6、header.html

I am the header

8、gulp import 运行gulp将页面进行合并最终会生成dist目录

9、/dist/index.html

        Gulp-html-import Example    

I am the header

Hello World

I am the footer

以上就是在HTML页面中引入外部HTML文件的解决方案的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1548119.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
HTML 与标签区别
上一篇 2025年12月21日 19:44:20
HTML Object 元素使用教程
下一篇 2025年12月21日 19:44:53

相关推荐

发表回复

登录后才能评论
关注微信