您的位置:首页 > 其它

关于网页头的问题

2007-03-29 10:56 225 查看
在一些网页中,有些人会把相同的头单独做成一个网页head.asp,而在别的页面的<body></body>之间用<!--include file="head.asp"-->调用,这样显得很方便。include 的作用就是相当于把被包含的文件中的代码放在使用include的地方,举个例子:
1.asp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<!--#include file="2.asp"-->
</body>
</html>

2.asp
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>

这时的1.asp其实就相当于:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
自己体会一下,一般情况下,被include的文件中,<html> <head>等标记都最好删除,否则可能引起显示混乱,因为相当于一个文件中有两对<html>等的标记了。

另外,一般来说,静态的HTML页面没有include功能,但是我们可以利用<script>的功能,举例如下:
//header.js:
aa="<head><title>aaa</title></head>";
document.write(aa);
//test.htm:
<script language="javascript" src="header.js"></script>
<body>hello</body>

OK, 你就可以看到include的效果了。

还有一个办法就是把静态页面改成动态页面,即把文件后缀改成asp,再使用<!--#include file="包含的文件名"-->,不过这样会降低速度,因为asp文件需要在IIS里先运行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: