日期:2010-03-15  浏览次数:20882 次

#include命令用于在多重页面上创建需重复使用的函数、页眉、页脚或者其他元素等。

#include 命令

通过使用#include命令,我们可以在服务器执行某个ASP文件之前,把另一个ASP文件插入这个文件中。#include命令用于在多重页面上创建需重复使用的函数、页眉、页脚或者其他元素等。

如何使用#include命令

这里有一个名为"mypage.asp"的文件:

以下为引用的内容:

<html>
<body>
<h3>Words of Wisdom:</h3>
<p><!--#include file="wisdom.inc"--></p>
<h3>The time is:</h3>
<p><!--#include file="time.inc"--></p>
</body>
</html>

这是"wisdom.inc"文件:

"One should never increase, beyond what is necessary,
the number of entities required to explain anything."

这是"time.inc"文件:

以下为引用的内容:
<%
Response.Write(Time)
%>

在浏览器中查看的源代码应该类似这样:

以下为引用的内容:

<html>
<body>
<h3>Words of Wisdom:</h3>
<p>"One should never increase, beyond what is necessary,
the number of entities required to explain anything."</p>
<h3>The time is:</h3>
<p>11:33:42 AM</p>
</body>
</html>

Including文件的语法:

如需在ASP中引用文件,请把#include命令置于注释标签之中:

以下为引用的内容:

<!--#include virtual="somefilename"-->

或者:

以下为引用的内容:

<!--#include file ="somefilename"-->

关键词Virtual

关键词virtual指明位于虚拟目录的路径。

如果名为"header.inc"位于名为/html的虚拟目录中,下面这行代码会插入文件"header.inc"中的内容:

以下为引用的内容:

<!-- #include virtual ="/html/header.inc" -->

关键词File

关键词File可指明一个相对的路径。相对路径起始于含有引用文件的目录。

假设某文件位于html文件夹的子文件夹headers