13-2 ?數定義檔?使用

Yn@AƨϥΦhӨơAiHNoǨƪwqgbƩwqɡAMANɮ׾ɤJ asp C

Ĥ@ؤ覡AOϥ Server-side include (SSI) 覡Nƪwq[JA榡pUG

<!--#include file="filename"-->
䤤 filename NɮתmAi[W۹ε|Ct@ؤ覡OG
<!--#include virtual="URLpath"-->
䤤 URLpath Nɮת}AiHO۹ε諸}C yܻAڭ̥iNƪwqgb@ɮפAYY@ӺnΨoӨơAunN۹ɮקQ SSI 覡ӥ[JYiC

bUCdҤAڭ̤Oϥ client-side include M server-side include ӥ[J@ǻPɶơG

Example]timeDisplay02.asp^G

WzdҪlɦpUG

lɡ]timeDisplay02.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="ϥΨƩwqɮרܲ{bɶ"%>
<!--#include file="head.inc"-->
<hr>

<p>timeFunctionRunAtClient.js:<br>
<script src="timeFunctionRunAtClient.js"></script>
<script>
document.write('{bOu' + currentTime()+ 'vI<br>');
document.write('ѬOu' + currentDay() + 'vI<br>');
</script>

<p>timeFunctionRunAtServer.inc:<br>
<!--#include file="timeFunctionFunAtServer.inc"-->
<%
Response.write('{bOu' + currentTime()+ 'vI<br>');
Response.write('ѬOu' + currentDay() + 'vI<br>');
%>

<hr>
<!--#include file="foot.inc"-->

䤤Aϥ client-side include ҥ[Jɮ׬O timeFunctionRunAtClient.jsG

lɡ]timeFunctionRunAtClient.js^G]ǦϰUYi^
function currentTime(){		// ^Dz{bɶ
	var today = new Date();
	return(today.toLocaleString());
}

function currentDay(){		// ^ǤѬPX
	var today = new Date();
	var day = today.getDay();	// oѬOPX
	var conversion=["", "@", "G", "T", "|", "", ""];
	return("P"+conversion[day]);
}

Өϥ server-side include ҥ[Jɮ׬O timeFunctionRunAtServer.incG

lɡ]timeFunctionFunAtServer.inc^G]ǦϰUYi^
<%
function currentTime(){		// ^Dz{bɶ
	var today = new Date();
	return(today.toLocaleString());
}

function currentDay(){		// ^ǤѬPX
	var today = new Date();
	var day = today.getDay();	// oѬOPX
	var conversion=["", "@", "G", "T", "|", "", ""];
	return("P"+conversion[day]);
}
%>

oɮתeXG@ˡAߤ@POAtimeFunctionRunAtServer.inc bƫeU[WF <% M %>C

Hint
SSI ɮתeA]iH]t HTML ΥΤݪ JavaScriptBVBScript C

bϥ SSI ɡAXInSO`NG

pGƱNYDZ`ΪƩb@ɮסAȤݤΦAݳoǨơAɧڭ̴NiHϥβĤGؤ覡ŪJƩwqɡAkܹ JavaScript bΤݩҨϥΪ client-side includeARO榡pUG
<script language=jscript runat=server src=timeFunction.js></script>
ШUCdҡG

Example]timeDisplay03.asp^G

WzdҪlɦpUG

lɡ]timeDisplay03.asp^G]ǦϰUYi^
<%@language=jscript%>
<%title="ϥΨƩwqɮרܲ{bɶ"%>
<!--#include file="head.inc"-->
<hr>

<p>timeFunction.js run at client:<br>
<script src="timeFunction.js"></script>
<script>
document.write('{bOu' + currentTime()+ 'vI<br>');
document.write('ѬOu' + currentDay() + 'vI<br>');
</script>

<p>timeFunction.js run at server:<br>
<script language=jscript runat=server src="timeFunction.js"></script>
<%
Response.write('{bOu' + currentTime()+ 'vI<br>');
Response.write('ѬOu' + currentDay() + 'vI<br>');
%>

<hr>
<!--#include file="foot.inc"-->

bWzdҤAL׬O client-side include άO server-side includeAҥ[JƩwqɮ׳O timeFunction.jsA䤺epUG

lɡ]timeFunction.js^G]ǦϰUYi^
function currentTime(){		// ^Dz{bɶ
	var today = new Date();
	return(today.toLocaleString());
}

function currentDay(){		// ^ǤѬPX
	var today = new Date();
	var day = today.getDay();	// oѬOPX
	var conversion=["", "@", "G", "T", "|", "", ""];
	return("P"+conversion[day]);
}

]ڭ̥iHg@ӨƩwqɡAPɦbAMΤݳϥΦɮסApNiHFu@bv]g@ƦbAMΤݦ@Ρ^̰ҬɡI

Hint
Ъ`NG
  • AΦkƩwqɡAiH]t HTML lXC
  • ƩwqɪɦWA̦nO jsAHקK]s睊ӾɭPe欰@pC


JScript {]pPΡGΩAݪ ASP