javascriptasp教程第十三课--include文件
ServerSideIncludes:
ExperiencedJavaScriptprogrammersknowthatcodereuseisgood.ExperiencedJavaScriptprogrammersalsoknowthatJavaScriptfunctionsaredatatypes.
So,weshouldbeabletostoreaJavaScriptfunctioninsideaSessionVariableoranApplicationVariable,right?Unfortunately,no.ThewaytoreuseJavaScriptfunctionsacrossmanypagesistouseSSI:ServerSideIncludes.
<%@LANGUAGE="JavaScript"%> <HTML> <HEAD> <!--#includefile="script13a.asp"--> <TITLE><%Response.Write(whatTimeIsIt())%></TITLE> </HEAD> <BODY> <% Response.Write("Thedateandtimeare"+DateTime+"<BR><BR>\r") Response.Write("Tomorrow"sdateis"+Tomorrow+"<BR><BR>\r") Response.Write("Tomorrowwillbea"+findDayOfWeek(Tomorrow)+"\r") %> </BODY> </HTML>
ClickHeretorunthescriptinanewwindow.
Lookatthecodeforscript13.asp.Itcallsforanincludefileviathisline:
<HTML> <HEAD> <TITLE>10:57:20AM</TITLE> </HEAD> <BODY> Thedateandtimeare4/11/200310:57:20AM<BR><BR> Tomorrow"sdateis4/12/2003<BR><BR> TomorrowwillbeaSaturday </BODY> </HTML>
ThefinalHTMLcodelookssoniceandsimple.You"dneverknowthattheDate()objecthadbeentorndownandputbacktogether.Belowistheincludefile.
<% functionwhatTimeIsIt() { varm=newDate() varminute=m.getMinutes() varsecond=m.getSeconds() varampm=false if(minute>=0&&minute<10) { minute=("0"+minute) } if(second>=0&&second<10) { second=("0"+second) } varhours=m.getHours() if(hours>12) { ampm=true hours=hours-12 } if(hours==12) { ampm=true } if(hours==0) { hours=hours+12 ampm=false } if(ampm) { ampm="pm" } else { ampm="am" } varmyTime=hours+":"+minute+":"+second+ampm returnmyTime; } varDateTime=newDate(); varMonth=(DateTime.getMonth()+1)+"/"; varDay=DateTime.getDate()+"/"; varYear=DateTime.getFullYear(); varDateTime=Month+Day+Year+""+whatTimeIsIt(); varTomorrow=newDate() Tomorrow.setDate(Tomorrow.getDate()+1) Month=(Tomorrow.getMonth()+1)+"/" Day=Tomorrow.getDate()+"/" Year=Tomorrow.getFullYear() Tomorrow=Month+Day+Year functionfindDayOfWeek(DateInQuestion) { //formatforDateInQuestionismm/dd/yyyyorm/d/yyyy //andpresumesthe/"sarepresent. myRegExp=/\d{1,2}\// myMonth=(parseInt(DateInQuestion.match(myRegExp))-1) myRegExp=/\/\d{1,2}\// myDay=newString(DateInQuestion.match(myRegExp)) myDay=parseInt(myDay.substring(1,myDay.length)) myRegExp=/\/\d{4}/ myYear=newString(DateInQuestion.match(myRegExp)) myYear=parseInt(myYear.substring(1,myYear.length)) DateInQuestion=newDate(myYear,myMonth,myDay) DayOfWeek=newArray DayOfWeek[0]="Sunday" DayOfWeek[1]="Monday" DayOfWeek[2]="Tuesday" DayOfWeek[3]="Wednesday" DayOfWeek[4]="Thursday" DayOfWeek[5]="Friday" DayOfWeek[6]="Saturday" DayOfWeek=DayOfWeek[DateInQuestion.getDay()] returnDayOfWeek; } %>
Imaginethatyouhad50pagesthatallneedwhatTimeIsIt(),findDayOfWeek(),DateTime,andTomorrow.Youwouldn"twant50differentcopiesofthesefunctionsandvariables.No,youwouldratherhaveasinglecopyoftheseitemssothatyoucouldmanipulatethesinglecopyandexecuteyourupdatestoall50pagesatonce.
Nowyouknowhowtodothat.
MovingForward:
ThisconcludesSection03.NextupServerandErrorobjectsinSection04.
相关文章
- ASP.netMVC文件下载
- 【说站】python关闭文件的两种方法
- 【说站】php有哪些文件包含漏洞
- 震惊!这个超16K star的项目居然只有README文件!
- 超全总结:Go语言如何操作文件
- Uncaught SyntaxError: Cannot use import statement outside a module的解决方法(使用Es6语法引入js对象文件报错)
- SQLServer 错误 7903 表错误:在对象 ID O_ID,索引 ID I_ID,分区 ID PN_ID,列 ID C_ID 的 FileStream 目录中发现孤立文件“FILE”。 故障 处理 修复 支持远程
- 初学者教程:用Linux制作ISO文件(linux制作iso文件)
- Linux下安全删除某些文件的方法(linux删除部分文件)
- Linux中查看文件详细信息的方法(linux显示文件信息)
- java代码解压rar文件时报错,badRarArchive详解编程语言
- 删除文件的迅速命令:Linux中的RM(linux中rm)
- Linux下的文件魔力:探索精彩的文件世界(linux中什么是文件)
- 如何解决MySQL DLL文件缺失问题(mysqldll)
- Linux文件占用查看简易教程(linux查看文件占用)
- 如何使用MySQL导入psc文件:简单步骤教程(mysql导入psc文件)
- Linux教程:新建文件完全攻略(linux新建文件)
- Linux运行文件命令简介及使用教程(linux运行文件命令)
- 使用MySQL实现高效稳定的200MB文件上传教程(mysql上传200m)
- javascript开发随笔二动态加载js和文件
- c#使用简单工厂模式实现生成html文件的封装类分享
- android开发教程之获取power_profile.xml文件的方法(android运行时能耗值)
- IIS支持exe文件下载配置方法附图