ASP学习笔记(12)--Include

本文介绍如何在ASP中利用SSI(Server Side Include)来包含JavaScript文件,实现跨页面使用同一份JavaScript代码,提高开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    写过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
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值