html代码复用各种方法

html代码复用各种方法,第1张

使用步骤:1.安装gulp以及gulp-file-include(NodeJs上)

2.新建gulpfile.js,配置 gulp-file-include:

var gulp =require('gulp')//引入gulp

var fileinclude  =require('gulp-file-include')//引入gulp-file-include

gulp.task('fileinclude', function() {

    gulp.src('src/**.html') .pipe(fileinclude({//gulp.src中存放要编译的文件

           prefix:'@@',

           basepath:'@file'

    })).pipe(gulp.dest('dist'))//gulp.dest中存放编译后的文件的存放地址

})

3.通过@@include('include/header.html')引用header.html

4.在命令行工具里,执行gulp fileinclude。执行完毕后,dist目录里就有相对应的html文件。

使用步骤:1.安装gulp-ejs(NodeJs上)

2.新建gulpfile.js,配置 gulp-file-include:

var gulp = require('gulp')//引入gulp

var ejs  = require('gulp-ejs')//引入gulp-ejs

gulp.task('ejs', function() {

     gulp.src('Views/Business/financeManage1.ejs')//gulp.src中存放要编译的文件

         .pipe(ejs({},{ext: '.html'}))//设置生成的文件后缀名为html

        .pipe(gulp.dest('Views/dist'))//gulp.dest中存放编译后的文件的存放地址

})

3.通过<%-include ../template.html  %>引用template.html

4.在命令行工具里,执行gulp ejs。执行完毕后,dist目录里就有相对应的html文件。

1.将项目放于本地服务器如xampp下

2.<iframe src="../template.html" width="100%" onload="reinitIframeEND()"></iframe>

3.function reinitIframe(){

        var iframe = document.getElementById("iframepage")

        console.log(iframe)

        try{

            var bHeight = iframe.contentWindow.document.body.scrollHeight

            var dHeight = iframe.contentWindow.document.documentElement.scrollHeight

            var height = Math.max(bHeight, dHeight)

            iframe.height = height

        }catch (ex){

            console.log(ex)

        }

}

var timer1 = window.setInterval("reinitIframe()", 500)//定时开始

function reinitIframeEND(){

        var iframe = document.getElementById("iframepage")

        console.log("3")

        try{

            var bHeight = iframe.contentWindow.document.body.scrollHeight

            var dHeight = iframe.contentWindow.document.documentElement.scrollHeight

            var height = Math.max(bHeight, dHeight)

            console.log(bHeight+":"+dHeight)

            iframe.height = height

      }catch (ex){

            console.log(ex)

     }

     // 停止定时

     window.clearInterval(timer1)

}

您好,非常荣幸能在此回答您的问题。以下是我对此问题的部分见解,若有错误,欢迎指出。展开全部

HTML复用,不需要任何模板就可以复用相同的内容

条件:控制页面布局显示就可以完成

示例:

主页

<!DOCTYPE html>

<html>

<head>

<meta charset='utf-8' />

<title>HTML调试</title>

<script type='text/javascript' src='js/jquery-1.8.0.min.js'></script>

<script src='js/zui.min.js' type='text/javascript' charset='utf-8'></script>

<script src='js/jquery-barcode.js' type='text/javascript' charset='utf-8'></script>

<link rel='stylesheet' type='text/css' href='css/zui.css' />

<style type='text/css'>

#container {

position: absolute

left: 0非常感谢您的耐心观看,如有帮助请采纳,祝生活愉快!谢谢!


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7470264.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-06
下一篇2023-04-06

发表评论

登录后才能评论

评论列表(0条)

    保存