1-3 ????二?事件驅?

t@رҰ JavaScript kAhOaƥXʡAAsŪJAYJ JavaScript {XAϥΪIsαҰʨLƹƥA~IJo JavaScript CKMϥΪ̶i椬ʡAJavaScript ѤFTӤتܵG `NQΦTؤتܵӻ JavaScript pHuƥXʡv覡ӰC

Hint
ҿסuƹƥv]Mouse events^AOs쪺ƹʧ@AҦpIY@ӳsBNв@vWBЪʵC

|ҨӻAڭ̤]iHN JavaScript gJs]Links^A]ϥΪI惡sAsh JavaScript {CҦpAڭ̥iHwqYӯSspUG

Example]alert01.htm^G

AUWzsAN|X{@ӽ|HĵiA~[pUG

AuuTwvsHĵiC{XpUG

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

<body>
<h2 align=center>|Hĵi</h2>
<hr>

<A href="javascript:alert('!@#$%^&amp;*!')">FA|ᮬI</A> 

<hr>
</body>
</html>

bWzdҤAڭ̬O JavaScript {Xgb href smAIs alert() ƨӲĵiܽ|HTCoӽdܴXӭIG

ڭ̤]iH@²檺BAANGe{bĵiAҦpG

Example]alert02.htm^G

WzdҪlɦpUG

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

<body>
<h2 align=center>ܺJɶĵi</h2>
<hr>

<script>
today = new Date();			// ͤ
hour = today.getHours();		// oɼ
minute = today.getMinutes();		// o
second = today.getSeconds();		// o
string = "JɶO"+hour+"I"+minute+""+second+"";	// sr
</script>
<a href="javascript:alert(string)">Jɶ</a>

<hr>
</body>
</html>

bWҤAڭ̥ͦr stringAsQUhɡAANreĵiC]MUخɶΪkA|b᭱ԭzC^

Yn檺{XӦhAKܳsAάOP@q{XnШϥΡAɧڭ̴NiHwqt~@ӨơAæbs榹ơAҦpG

Example]alert03.htm^G

WzdҪlɦpUG

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

<body>
<h2 align=center>ozĵi</h2>
<hr>

<SCRIPT>
function talk() {
	alert("OsAnܡH");
	alert("ASFOH");
	alert('pGCӤpijA@ˤťܡA');
	alert('ҦjHNgFHI');
	alert('Fg@AAAA20 Enter I');
	for (i=0; i<20; i++)
		alert(' ' + (i+1) + ' I');
	alert('HnĤpĤFI');
}
</SCRIPT>
<A href="javascript:talk()">o@Au|ᮬI</A> 

<hr>
</body>
</html>

Ъ`NbWҤArꪺñƬOѡu+vӹFAӼƾǪ[k]Oѡu+vӹFAJavaScript Ju+vɡA|P_kӹBlO_OƭȡAYOAhi[kCY@ӹBlOrAhrꪺñƹBC]MAbñƹBɡA|NƭȧκAB⤸ഫrC^

~AѤWzdҥiHݥXAJavaScript iH޸]"^γ޸]'^өwqrꪺ}lMC

bWzdҤAYεLajAAϥΪ̥i|uܫᮬUsA]ߤ@XkANOHD`qsC]bWindowsxiPɫ CtrlBAltBDel TӶ}Ҥu@޲zAHsC^ҦpG

Example]alert05.htm^G

HPǡAiHIWzsCWzdҪlɦpUG

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

<body>
<h2 align=center>SSFĵi</h2>
<hr>

<script>
function talk() {
	alert('An@d~樭...');
	for (i=0; i<1000; i++)
		alert(' ' + (i+1) + ' I');
	alert('IAQFF...A٭n100~ਫH...');
	for (i=0; i<100; i++)
		alert(' ' + (i+1) + ' I');
	alert('AuFCAӱRFI]LAɶ]ӦhFaH^_^^');
}
</script>
<a href="javascript:talk()">xANګݬݡI</a>

<hr>
</body>
</html>

ѤWz{XiHݥXAڭ̥iHwq@²檺禡 talk()AMϥ "javascript:talk()" Is禡C

Hint
pGnֳtXAФEnterAHESCۡA_h{i|A@C

ĵi\uObĵiάOǹFTAϥΪ̤]uuTwv_hLk~Ct@Ө㦳uG@v\઺صAOT{AdҦpUG

Example]confirm01.htm^G

bWzdҤAYϥΪ̫UuMjvsA|ͤUCT{G

ɭYUuTwvsA|sMؤjǭCYUuvsAhܡCdҪlɦpUG

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

<body>
<h2 align=center>ϥνT{ӽT{sʧ@</h2>
<hr>

<script>
function link2nthu() {
	answer = confirm("ATwnsMjܡH");
	if (answer)
		location.href="http://www.nthu.edu.tw";
}
</script>

<!-- Ĥ@ؤkGHƨӧu@ -->
<a href="javascript:link2nthu()">Mj</a><br>

<!-- ĤGؤkGN{XgbsCY^ǭȬuAhsܷsm -->
<a href="javascript:if (confirm('ATwnsjܡH')) location.href='http://www.nctu.edu.tw'">j</a><br>

<!-- ĤTؤkGϥ onClick ӧu@CY onClick ȬAhsL@ -->
<a href="http://www.ntu.edu.tw" onClick="return(confirm('ATwnsxjܡH'))">xj</a>

<hr>
</body>
</html>

bWzdҤAڭ̨ϥΤFTؤPkӱNT{ΩsG

Hint
FbΦbWzdҤ~A@Ө onClick iHIJoIƥA~Ӱ onClick ݩʦrꤤ{XC

ܵiHϥΪ̿J@Cr]ҥHS٬J^A]OoϥΪ̿J²覡CUOܵdҡG

Example]prompt01.htm^G

ϥΪ̫UuiѮvҵ{vɡA|ͦpUܵG

ϥΪ̥iHJҵ{NXAuTwvAN|sҵ{CdҪlɦpUG

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

<body>
<h2 align=center>ϥοJӨMws}</h2>
<hr>

<script>
function link2course() {
	course = prompt("пJҵ{NXG(webProgramming, scientificComputing, MSAR)", "webProgramming");
	if ((course=="webProgramming")||(course=="scientificComputing")||(course=="MSAR"))
		location.href="http://mirlab.org/jang/courses/" + course;
}
</script>

<a href="javascript:link2course()">iѮvҵ{</a>

<hr>
</body>
</html>

bWzdҤAڭ̨ϥ if ԭzӧP_ϥΪ̿JrO_ "cs3431" "cs3331" "cs3334" "cs5652" "isa5571"AYOAhoͥơCYOAhyX}AñNs즹}C]"||" N޿B⪺uΡvA "&&" hN޿B⪺uBvAo|b᭱`ԭzC^

Hint
ƹWAalert()Bconfirm() M prompt() O window 󪺤kAҥHnIsoǤkA㪺gkӬO window.alert()Bwindow.confirm() M window.prompt()AO]L̤ӱ`QΨAҥH]iHٲ window AIsoǨơC

uƥXʡv覡AO JavaScript ḇ`QϥΪ覡CU@`NлPuƥXʡv覡C


JavaScript {]pPΡGΩΤ