ASP学习笔记(12)--Include

来源:互联网 发布:淘宝卡马甲是什么意思 编辑:程序博客网 时间:2024/05/29 13:38

    写过javascript的人都知道javascript有一个很有用的个性,引用某些程序段,格式如下<script language="javascript" src="md5.js">  但是在asp中我们不能如此引用一个函数,必须使用SSI (server side include),格式如下<!--#include file="fortest17.asp"-->。跟所有编程语言的包含语句一样,我们只需要有一个这样的备份,然后就可以在不同的页面使用其中的函数以及数据了。

<%@ language=javascript %>
<!-- #include file="fortest17.asp" -->
<html>
 <head>
  <title><%Response.Write(whattime())%></title>
 </head>
 <body>
  <%
   Response.Write("the date and time is "+DateTime+"<br>/r");
  %>
 </body>
</html>

fortest17.asp


<%
 function whattime(){
  var todayTime=new Date();
  var theHour=todayTime.getHours();
  var theMinute=todayTime.getMinutes();
  var theSecond=todayTime.getSeconds();
  
  if(theHour>=0 && theHour<10){
   theHour="0"+theHour;
  }
  if(theMinute>=0 && theMinute<10){
   theMinute="0"+theMinute;
  }
  if(theSecond>=0 && theSecond<10){
   theSecond="0"+theSecond;
  }
  var theTime=theHour+":"+theMinute+":"+theSecond;
  return theTime;
 }
 
 var todayDate=new Date();
 var theYear=todayDate.getYear();
 var theMonth=todayDate.getMonth()+1;
 var theDate=todayDate.getDate();
 var theDate=theYear+"/"+theMonth+"/"+theDate;
 
 var DateTime=theDate+" "+whattime(); 
%>

    记得哦,在fortest17.asp中不能包含<%@ language=javascript %>的,否则会报错。其实道理也很显然,fortest17.asp就是test17.asp的一部分,其实两个文件可以写到一起的。include的好处就在于别的页面也可以使用这个fortest17.asp。

Google  
原创粉丝点击