
将多个html页面里引进相同的一个头部页面的方法如下:
1. iframe 包含法。
页头和页尾分别做成一个页面,然后通过iframe嵌入到调用的页面。这种方法在页头页尾高度固定的时候比较适用,因为当页头页尾高度不固定时,需要iframe根据页面内容自适应高度,比较麻烦。
简单代码结构示例:
<html>
<head>
<title>页面</title>
<style type="text/css">
.page{width:950pxmargin:0 auto}
</style>
</head>
<body>
<div class="page">
<iframe frameboder="0" scrolling="no" width="100%" height="80" src="head.html"></iframe>
<div>页面内容</div>
<iframe frameboder="0" scrolling="no" width="100%" height="80" src="foot.html"></iframe>
</div>
</body>
</html>
2. js包含法
页头和页尾改成外接js的形式,通过documen.write输出或其它js的输出的方法。这种方法在页头页尾需要修改时,不利于修改,也不好还原原先的html结构。
<html>
<head>
<title>页面</title>
<style type="text/css">
.page{width:950pxmargin:0 auto}
</style>
</head>
<body>
<div class="page">
<script type="text/javascript" href="head.js"></script>
<div>页面内容</div>
<script type="text/javascript" href="foot.js"></script>
</div>
</body>
</html>
3. shtml方法
运用服务端的包含方法,只需在页面中使用服务端包含命令<!--# include file="文件名称" -->,在被调用的页面嵌入页头和页脚即可。但此方法需要服务端支持ssi(server side include 服务端包含)功能。
<html>
<head>
<title>页面</title>
<style type="text/css">
.page{width:950pxmargin:0 auto}
</style>
</head>
<body>
<div class="page">
<!--#include file="head.html" -->
<div>页面内容</div>
<!--#include file="foot.html" -->
</div>
</body>
</html>
步骤
1、新建一网页文件“sample.html",用记事本或其它文本编辑软件(如UltraEdit)打开,输入如图所示的HTML代码。该网页文件包括一个蓝色的字符串,一个按钮和一个文本框。
2、JS代码可插入到”head"标签之间。编写Javascript代码,代码内容如图所示,并将该段代码复制到网页文件”sample.html“中标签”<head>"和“</head>之间,然后查看网页文件的显示内容。
能用 <include file=""> 答案补充 在JSP中使用把你的头部文件加在<body>之前
比如这样
<html>
<title></title>
<jsp:include page="/student/top.jps"/>
"sutdent"是一个文件夹/top.jsp
<body>
</body>
</html>
或者可以使用你精通的<IFRAME></IFRAME>调入静态页面文档,也可以将页面的头和尾部分别改写为JS文档,使用<script language="javascript" src="***.js"></script>调入
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)