5-2 ?數定義檔??使??

Ynƨϥ JavaScript ơAiNoDZ`Ϊƶ׾@ӨƩwqɮסAAHUC覡ӱNƵ{X[JG
<script src="Ʃwqɮ.js"></script>
WzdҤƩwqɪɦWO "js"AouO@ߺDAϥΪ̤]iHΨ䥦NɦWCOY䤣ɮסAä|LX~TAoOnSO`NaC

ϥΨƩwqɪnBOG

HUoӽdҡANOϥγoؤkӥ]t@ JavaScript ƩwqɮסAɮשwqFӨơAiOǦ^{bɶPPXAe{ĪGpUG

Example]timeDisplay02.htm^G

ϥΪ̫Uuܲ{bɶvɡAsN|hIswq time.js currentTime() Ho{bɶAñNGܩĵiCdҭlXpUG

lɡ]timeDisplay02.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>ϥΨƩwqɮרܲ{bɶ</h2>
<hr>

<script src="time.js"></script>
<a href="javascript:alert('{bOu' + currentTime()+ 'vI')">ܲ{bɶ</a><br>
<a href="javascript:alert('ѬOu' + currentDay() + 'vI')">ܬPX</a><br>

<hr>
</body>
</html>

bWҤAڭ̥椬B޸ (") γ޸ (')AHհϤ href ҥΪr JavaScript ҥΪrCWҥ]tF@ JavaScript Ʃwq time.jsAlɮפepUG

lɡ]time.js^G]ǦϰUYi^
// P
function currentTime(){		// ^Dz{bɶ
	var today = new Date();
	var hour = today.getHours();
	var minute = today.getMinutes();
	var second = today.getSeconds();
	var prepand = (hour>12)? "U":"W";
	hour = (hour>12)? hour-12:hour;
	return(prepand + hour + " I " + minute + "  " + second + " ");
}

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

]ɶMΪkAШѫeXC^

ڭ̤]iHҤlAiUʽCG

Example]docProp01.htm^G

lɮפepUG

lɡ]docProp01.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>"document" ʽC</h2>
<hr>
<a href="http://www.nthu.edu.tw">Mj</a><br>
<a href="http://www.nctu.edu.tw">j</a><br>
<a href="http://www.ntu.edu.tw">xj</a>
<hr>

<script src="listProp.js"></script>
<p><h3>"document" ʽCG</h3>
<p><script>listProp(document, "document")</script>

<hr>
</body>
</html>

Wzdҥ]tF@ listProp.js ɮסA䤺epUG

lɡ]listProp.js^G]ǦϰUYi^
// CLʽ
function listProp(obj, objName) {
	for (var i in obj)
		document.writeln(objName+".<font color=red>"+i+"</font> = <font color=green>"+obj[i]+"</font><br>");
}

bWz{XAڭ̥ΨF for-in jAذjSOAΩCX@Ӫ󪺩ҦʽC]󪺩ʽAШU@C^


JavaScript {]pPΡGΩΤ