1-3 ����覡�G�G�ƥ��X��

¥t¤@ºØ±Ò°Ê JavaScript ªº¤èªk¡A«h¬O¾a¨Æ¥óÅX°Ê¡A´«¨¥¤§¡A·íÂsÄý¾¹Åª¤Jºô­¶«á¡A§Y¸ü¤J JavaScript µ{¦¡½X¡A¦ý¥²¶·µ¥¨ì¨Ï¥ÎªÌÂI¿ï³sµ²©Î±Ò°Ê¨ä¥L·Æ¹«¨Æ¥ó¡A¤~¯àIJµo JavaScript ªº°õ¦æ¡C¬°¤è«K©M¨Ï¥ÎªÌ¶i¦æ¤¬°Ê¡AJavaScript ´£¨Ñ¤F¤T­Ó¤º«Øªº¹ï¸Üµøµ¡¡G ¥»¸`±N§Q¥Î¦¹¤TºØ¤º«Øªº¹ï¸Üµøµ¡¨Ó»¡©ú JavaScript ¦p¦ó¥H¡u¨Æ¥óÅX°Ê¡vªº¤è¦¡¨Ó°õ¦æ¡C

Hint
©Ò¿×¡u·Æ¹«¨Æ¥ó¡v¡]Mouse events¡^¡A«üªº¬O¯à¥ÑÂsÄý¾¹°»´ú¨ìªº·Æ¹«°Ê§@¡A¨Ò¦pÂI¿ï¬Y¤@­Ó³sµ²¡B±N´å¼Ð²¾¨ì¤@ªº¼v¹³¤W¡B´å¼Ðªº²¾°Êµ¥¡C

Á|¨Ò¨Ó»¡¡A§Ú­Ì¤]¥i¥H±N JavaScript ª½±µ¼g¤Jºô­¶ªº³sµ²¡]Links¡^¤§¤¤¡A¦]¦¹·í¨Ï¥ÎªÌÂI¿ï¦¹³sµ²¡AÂsÄý¾¹«h°õ¦æ¬ÛÃöªº JavaScript µ{¦¡¡C¨Ò¦p¡A§Ú­Ì¥i¥H©w¸q¬Y­Ó¯S®í³sµ²¦p¤U¡G

Example¡]alert01.htm¡^¡G

·í§A«ö¤U¤W­z³sµ²¡A´N·|¥X²{¤@­Ó½|¤HªºÄµ§iµøµ¡¡A¥~Æ[¦p¤U¡G

§A¥u¯à«ö¡u½T©w¡v«ö¶s¥HÃö³¬¦¹Äµ§iµøµ¡¡C­ìºô­¶µ{¦¡½X¦p¤U¡G

­ì©lÀÉ¡]alert01.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<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;*!')">«ö¤F§A·|«á®¬³á¡I</A> 

<hr>
</body>
</html>

¦b¤W­z½d¨Ò¤¤¡A§Ú­Ì¬O§â JavaScript ªºµ{¦¡½Xª½±µ¼g¦b href ªº³sµ²¦ì¸m¡Aª½±µ©I¥s alert() ¨ç¼Æ¨Ó²£¥Íĵ§iµøµ¡¨ÃÅã¥Ü½|¤H°T®§¡C³o­Ó½d¨ÒÅã¥Ü´X­Ó­«ÂI¡G

§Ú­Ì¤]¥i¥H¥ý°õ¦æ¤@¨Ç²³æªº¹Bºâ¡A¦A±Nµ²ªG§e²{¦bĵ§iµøµ¡¡A¨Ò¦p¡G

Example¡]alert02.htm¡^¡G

¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]alert02.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<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+"¬í";	// ³s±µ¦r¦ê
</script>
<a href="javascript:alert(string)">ºô­¶¸ü¤J®É¶¡</a>

<hr>
</body>
</html>

¦b¤W¨Ò¤¤¡A§Ú­Ì¥ý²£¥Í¦r¦ê string¡A·í³sµ²³Q«ö¤U¥h®É¡A¦A±N¦r¦ê°e¦Üĵ§iµøµ¡¡C¡]¦³Ãö©ó¤é´Áª«¥ó©M¦UºØ®É¶¡ªº¥Îªk¡A·|¦b«á­±¸Ô­z¡C¡^

­Y­n°õ¦æªºµ{¦¡½X¤Ó¦h¡A¤£¤è«K©ñ¦Ü³sµ²¤§¤¤¡A©Î¬O¦P¤@¬qµ{¦¡½X­n¤ÏÂШϥΡA¦¹®É§Ú­Ì´N¥i¥H©w¸q¥t¥~¤@­Ó¨ç¼Æ¡A¨Ã¦b³sµ²¤¤°õ¦æ¦¹¨ç¼Æ¡A¨Ò¦p¡G

Example¡]alert03.htm¡^¡G

¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]alert03.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>Åo¨½¥z­öªºÄµ§iµøµ¡</h2>
<hr>

<SCRIPT>
function talk() {
	alert("¤£¬O¥s§A¤£­n«ö¶Ü¡H");
	alert("¬°¤°»ò§A¤S«ö¤F©O¡H");
	alert('¦pªG¨C­Ó¤p«Ä³£¹³§A¤@¼Ë¤£Å¥¸Ü¡A');
	alert('¨º»ò©Ò¦³¤j¤H¤£´N³£§ì¨g¤F¡H¡I');
	alert('¬°¤FÃg»@§A¡A§A¥²¶·¦A«ö20¦¸ Enter Áä¡I');
	for (i=0; i<20; i++)
		alert('²Ä ' + (i+1) + ' ¦¸¡I');
	alert('¥H«á­n·í¨Ä¤p«Ä¤F¡I');
}
</SCRIPT>
<A href="javascript:talk()">³o¤@¦¸§A¯uªº·|«á®¬¡I</A> 

<hr>
</body>
</html>

½Ðª`·N¦b¤W¨Ò¤¤¡A¦r¦êªº¨Ã±Æ¬O¥Ñ¡u+¡v¨Ó¹F¦¨¡A¦Ó¼Æ¾Çªº¥[ªk¤]¬O¥Ñ¡u+¡v¨Ó¹F¦¨¡AJavaScript ¹J¨ì¡u+¡v®É¡A·|¥ý§PÂ_¥ª¥k¨â­Ó¹Bºâ¤l¬O§_¥þ¬O¼Æ­È¡A­Y¬O¡A«h¶i¦æ¥[ªk¡C­Y¦³¤@­Ó¹Bºâ¤l¬O¦r¦ê¡A«h°õ¦æ¦r¦êªº¨Ã±Æ¹Bºâ¡C¡]·íµM¡A¦b°õ¦æ¨Ã±Æ¹Bºâ®É¡A·|±N¼Æ­È§ÎºAªº¹Bºâ¤¸¥ýÂà´«¦¨¦r¦ê¡C¡^

¦¹¥~¡A¥Ñ¤W­z½d¨Ò¥i¥H¬Ý¥X¡AJavaScript ¥i¥H¥ÎÂù¤Þ¸¹¡]"¡^©Î³æ¤Þ¸¹¡]'¡^¨Ó©w¸q¦r¦êªº¶}©l©Mµ²§ô¡C

¦b¤W­z½d¨Ò¤¤¡A­Y§ï¥ÎµL½a°j°é¡A¨º»ò¡A¨Ï¥ÎªÌ¥i¯à·|¯uªº«Ü«á®¬«ö¤U¦¹³sµ²¡A¦]¬°°ß¤@¸õ¥Xªº¤èªk¡A´N¬O¥H«D±`¤â¬q°±¤îÂsÄý¾¹ªº°õ¦æ¡C¡]¦bWindows¥­¥x¥i¦P®É«ö Ctrl¡BAlt¡BDel ¤TÁä¨Ó¶}±Ò¤u§@ºÞ²z­û¡A¥HÃö³¬ÂsÄý¾¹¡C¡^¨Ò¦p¡G

Example¡]alert05.htm¡^¡G

¤£«H¨¸ªº¦P¾Ç¡A¥i¥Hª½±µÂI¿ï¤W­zºô­¶ªº³sµ²¡C¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]alert05.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>¨S§¹¨S¤FªºÄµ§iµøµ¡</h2>
<hr>

<script>
function talk() {
	alert('§A­n«ö¤@¤d¦¸¤~¯à²æ¨­...');
	for (i=0; i<1000; i++)
		alert('²Ä ' + (i+1) + ' ¦¸¡I');
	alert('«¢«¢¡I§A³Q§ÚÄF¤F...§AÁÙ­n«ö100¦¸¤~¯à¨«¤H...');
	for (i=0; i<100; i++)
		alert('²Ä ' + (i+1) + ' ¦¸¡I');
	alert('§A¯uªº«ö§¹¤F­C¡A¤Ó±R«ô¤F¡I¡]¤£¹L§A®É¶¡¤]¤Ó¦h¤F§a¡H^_^¡^');
}
</script>
<a href="javascript:talk()">¦³Áx§A´Nµ¹§Ú«ö¬Ý¬Ý¡I</a>

<hr>
</body>
</html>

¥Ñ¤W­zµ{¦¡½X¥i¥H¬Ý¥X¡A§Ú­Ì¥i¥H©w¸q¤@­Ó²³æªº¨ç¦¡ talk()¡AµM«á¨Ï¥Î "javascript:talk()" ª½±µ©I¥s¦¹¨ç¦¡¡C

Hint
¦pªG­n§Ö³t¸õ¥X¡A½Ð¤ÅÀ£µÛEnterÁä¡A§ï¥HESCÁäÀ£µÛ¡A§_«hµ{¦¡¦³¥i¯à·|¦A°õ¦æ¤@¦¸¡C

ĵ§iµøµ¡ªº¥\¯à¥u¬O¦bĵ§i©Î¬O¶Ç¹F°T®§¡A¨Ï¥ÎªÌ¤]¥u¯à«ö¡u½T©w¡v§_«hµLªkÄ~Äò¡C¥t¤@­Ó¨ã¦³¡u¤G¿ï¤@¡v¥\¯àªº¤º«Øµøµ¡¡A¬O½T»{µøµ¡¡A½d¨Ò¦p¤U¡G

Example¡]confirm01.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A­Y¨Ï¥ÎªÌ«ö¤U¡u²M¤j­º­¶¡vªº³sµ²«á¡A·|²£¥Í¤U¦C½T»{µøµ¡¡G

¦¹®É­Y«ö¤U¡u½T©w¡v«ö¶s¡Aºô­¶·|³s¨ì²MµØ¤j¾Ç­º­¶¡C­Y«ö¤U¡u¨ú®ø¡v«ö¶s¡A«hºô­¶ºû«ù¤£ÅÜ¡C¦¹½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]confirm01.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<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("§A½T©w­n³s¨ì²M¤jªº­º­¶¶Ü¡H");
	if (answer)
		location.href="http://www.nthu.edu.tw";
}
</script>

<!-- ²Ä¤@ºØ¤èªk¡G¥H¨ç¼Æ¨Ó§¹¦¨¦¹¶µ¤u§@ -->
<a href="javascript:link2nthu()">²M¤j­º­¶</a><br>

<!-- ²Ä¤GºØ¤èªk¡G±Nµ{¦¡½X¼g¦b³sµ²¤º¡C­Y¦^¶Ç­È¬°¯u¡A«h³s¦Ü·s¦ì¸m -->
<a href="javascript:if (confirm('§A½T©w­n³s¨ì¥æ¤jªº­º­¶¶Ü¡H')) location.href='http://www.nctu.edu.tw'">¥æ¤j­º­¶</a><br>

<!-- ²Ä¤TºØ¤èªk¡G¨Ï¥Î onClick ¨Ó§¹¦¨¦¹¶µ¤u§@¡C­Y onClick ªº­È¬°°°¡A«h³sµ²µL§@¥Î -->
<a href="http://www.ntu.edu.tw" onClick="return(confirm('§A½T©w­n³s¨ì¥x¤jªº­º­¶¶Ü¡H'))">¥x¤j­º­¶</a>

<hr>
</body>
</html>

¦b¤W­z½d¨Ò¤¤¡A§Ú­Ì¨Ï¥Î¤F¤TºØ¤£¦Pªº¤èªk¨Ó±N½T»{µøµ¡¥Î©ó³sµ²¤§¤¤¡G

Hint
°£¤F¦b¥Î¦b¤W­z½d¨Ò¤§¥~¡A¤@¯ë¦Ó¨¥ onClick ¥i¥HIJµoÂIÀ»¨Æ¥ó¡AÄ~¦Ó°õ¦æ onClick Äݩʦr¦ê¤¤ªºµ{¦¡½X¡C

´£¥Üµøµ¡¥i¥HÅý¨Ï¥ÎªÌ¿é¤J¤@¦C¦r¦ê¡]©Ò¥H¤SºÙ¬°¿é¤Jµøµ¡¡^¡A¤]¬O¨ú±o¨Ï¥ÎªÌ¿é¤Jªº³Ì²³æ¤è¦¡¡C¤U­±¬O´£¥Üµøµ¡ªº½d¨Ò¡G

Example¡]prompt01.htm¡^¡G

·í¨Ï¥ÎªÌ«ö¤U¡u±i¦Ñ®vªº½Òµ{¡v®É¡A·|²£¥Í¦p¤Uªº´£¥Üµøµ¡¡G

¨Ï¥ÎªÌ¥i¥H¿é¤J¬ÛÃöªº½Òµ{¥N½X¡A«ö¡u½T©w¡v«á¡Aºô­¶´N·|³sµ²¨ì¬ÛÃö½Òµ{­º­¶¡C¦¹½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]prompt01.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>¨Ï¥Î¿é¤Jµøµ¡¨Ó¨M©w³sµ²ºô§}</h2>
<hr>

<script>
function link2course() {
	course = prompt("½Ð¿é¤J½Òµ{¥N½X¡G(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>

¦b¤W­z½d¨Ò¤¤¡A§Ú­Ì¨Ï¥Î if ±Ô­z¨Ó§PÂ_¨Ï¥ÎªÌ¿é¤Jªº¦r¦ê¬O§_µ¥©ó "cs3431" ©Î "cs3331" ©Î "cs3334" ©Î "cs5652" ©Î "isa5571"¡A­Y¤£¬O¡A«h¤£µo¥Í¥ô¦ó¨Æ¡C­Y¬O¡A«h³y¥X¬ÛÃöºô§}¡A¨Ã±Nºô­¶³sµ²¨ì¦¹ºô§}¡C¡]"||" ¥NªíÅÞ¿è¹Bºâªº¡u©Î¡v¡A¦Ó "&&" «h¥NªíÅÞ¿è¹Bºâªº¡u¥B¡v¡A³o³¡¤À·|¦b«á­±³¹¸`¸Ô­z¡C¡^

Hint
¨Æ¹ê¤W¡Aalert()¡Bconfirm() ©M prompt() ³£¬O window ª«¥óªº¤èªk¡A©Ò¥H­n©I¥s³o¨Ç¤èªk¡A§¹¾ãªº¼gªkÀ³¸Ó¬O window.alert()¡Bwindow.confirm() ©M window.prompt()¡A¦ý¬O¦]¬°¥L­Ì¤Ó±`³Q¥Î¨ì¡A©Ò¥H¤]¥i¥H¬Ù²¤ window ¦¹ª«¥ó¡Aª½±µ©I¥s³o¨Ç¨ç¼Æ¡C

¡u¨Æ¥óÅX°Ê¡vªº°õ¦æ¤è¦¡¡A¬O JavaScript ¦bºô­¶¤¤³Ì±`³Q¨Ï¥Îªº¤è¦¡¡C¤U¤@¸`±N¤¶²Ð»Pªí³æ¬ÛÃöªº¡u¨Æ¥óÅX°Ê¡v°õ¦æ¤è¦¡¡C


JavaScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©óºô­¶¥Î¤áºÝ