1-2 ����覡�@�G�`�ǰ���

°ò¥»¦Ó¨¥¡A§Ú­Ì¥i¦³¨âºØ¤è¦¡¨Ó¨Ï¥Î JavaScript ©óºô­¶¤§¤¤¡G
  1. ´`§Ç°õ¦æ¡]Sequential Execution¡^: ÂsÄý¾¹Åª¤Jºô­¶«á¡A§Y¸ü¤J¨Ã°õ¦æ JavaScript µ{¦¡½X¡A³Ì«á±Nµ²ªGª½±µ§e²{¦bÂsÄý¾¹¤W¡C
  2. ¨Æ¥óÅX°Ê¡]Event Driven¡^: ÂsÄý¾¹Åª¤Jºô­¶«á¡A§Y¸ü¤J JavaScript µ{¦¡½X¡A¦ý¥²¶·µ¥¨ì¨Ï¥ÎªÌÂI¿ï³sµ²©Î¼v¹³¡A©Î¬O±Ò°Ê¨ä¥L·Æ¹«¨Æ¥ó¡]¨Ò¦p·í·Æ¹«Â÷¶}¬Y­Ó¼v¹³¡^¡A¤~¯àIJµo JavaScript ªº°õ¦æ¡C
¥»¸`±N¥ý¤¶²Ð¡u´`§Ç°õ¦æ¡vªº JavaScript µ{¦¡½X¡A¨Ã¥H³Ì²³æªº½d¨Ò¨Ó±a»âŪªÌ¶i¤J JavaScript ªº¥@¬É¡C¦Ü©ó¡u¨Æ¥óÅX°Ê¡vªº JavaScript µ{¦¡½X³]­p¡A±N·|¦b¤U¤@¸`»¡©ú¡C

­Y­n¦b HTML ­ì©l½X¤¤¥[¤J JavaScript ªºµ{¦¡½X¡A¥u­n¨Ï¥Î <script> ¼ÐÅÒ§Y¥i¡A¨ä°ò¥»®æ¦¡¦p¤U¡G

<script language=javascript> JavaScript µ{¦¡½X ... </script> ¦b¤W­z°ò¥»®æ¦¡¤¤¡A¼ÐÅÒ¤¤ªº¤j¤p¼g¨ÃµL¥ô¦ó¼vÅT¡]¦]¦¹¡uscript¡v¥i¼g¦¨¡uSCRIPT¡v¡A¡ulanguage¡v¥i¼g¦¨¡uLANGUAGE¡v¡C¡^¡C¦¹¥~¡AJavaScript/JScript §Y¬O <script> ¼ÐÅÒªº¹w³]»y¨¥¡A¦]¦¹¡ulanguage=javascript¡v©Î¡ulanguage=jscript¡v¤]¥i¥H§¹¥þ¬Ù²¤¡C¡]­Y§A¨Ï¥Îªº»y¨¥¬O VBScript ©Î PerlScript¡A«h¤@©w­n¥[¤W language=VBScript ©Î language=PerlScript¡C¡^

Hint
ÁöµM HTML ¤ºªº JavaScript ¼ÐÅÒ¬O¥i¥H¤£¤À¤j¤p¼g¡A¦ý¬O¼ÐÅÒ¤º³¡ªº JavaScript µ{¦¡½X¥»¨­·|°Ï¤À¤j¤p¼g¡A³o¬O­n¯S§Oª`·Nªº¦a¤è¡I

­º¥ý§Ú­Ì¨Ó¬Ý¤@­Ó´`§Ç°õ¦æªºÂ²³æ½d¨Ò¡A¦¹½d¨Ò·|¦bºô­¶¤W¦L¥X¡uHello World!¡v¡A¦p¤U¡G

Example¡]hello01.htm¡^¡G

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

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

<body>
<h2 align=center>§Q¥Î JavaScript ¨Ó¦L¥X "Hello World!"</h2>
<hr>

<script language="javascript">
	str = "Hello World!";
	document.write(str);
</script>

<hr>
</body>
</html>

¨ä¤¤ str ¬O¤@­Ó¦r¦êÅܼơA¨ä­È¬° "Hello World!"¡Adocument «h¬O¤@­Óª«¥ó¡A¥Nªíµ{¦¡½X©Ò¦bªº¤å¥ó¡Awrite «h¬O document ªº¤@­Ó¤èªk¡A¥i±N¤@­Ó¦r¦ê¦L¥X©óÂsÄý¾¹¡A¦]¦¹ document.write(str) ªº§@¥Î´N¬O±N "Hello World!" Åã¥Ü¦bÂsÄý¾¹¤§¤W¡C

§Ú­Ì¦b«e¤@¤p¸`´£¹L¡AJavaScript ¬O¤@­Ó¥Hª«¥ó¬°°ò¦ªº»y¨¥¡A¦]¦¹´X¥G©Ò¦³ªºÅܼƦb JavaScript ¤¤³£¬O¤@­Óª«¥ó¡A¤@­Óª«¥ó³q±`¦³¤@¨Ç©Ê½è¡]Property¡^©M¤èªk¡]Method¡^¡A¦Ó»Pª«¥ó¬ÛÃöªº¨ç¼Æ³q±`´N³Q©w¸q¦¨ª«¥óªº¤èªk¡]©Î¬O¥\¯à¡^¡CÁ|¨Ò¨Ó»¡¡A§Ú­Ì¥i¥H§â¤@­Ó·LªiÄl¬Ý¦¨¤@­Óª«¥ó¡A¨º»ò·LªiÄlªºÃC¦â¡]Color¡^´N¬O¤@­Ó©Ê½è¡A®e¶q¡]Volume¡^¤S¬O¥t¤@ºØ©Ê½è¡A¦Ó§Ú­Ì¥i¥H§â¡u¥[¼ö¡v¡]Heat¡^¬Ý¦¨·LªiÄlªº¤@­Ó¤èªk¡]©Î¬O¨ç¼Æ¡^¥¦ªº¿é¤J°Ñ¼Æ¦³¨â­Ó¡A²Ä¤@­Ó°Ñ¼Æ¬O©ñ¶i·LªiÄlªºª««~¡A²Ä¤G­Ó°Ñ¼Æ«h¬O¥[¼öªº¬í¼Æ¡C¦]¦¹¹ï©ó¤@­Ó®e¶q¬°¤K¤½¤Éªº¥Õ¦â·LªiÄl A¡AA.color ´N¬O white¡AA.volume ´N¬O 8¡A¦Ó A.heat("§N¤ô", 30) ¶Ç¦^­È¥i¯à¬O "·Å¤ô"¡]§N¤ô¥[¼ö 30 ¬íÅܦ¨·Å¤ô¡^¡A¦Ó A.heat("§N¤ô", 300) ¶Ç¦^­È¥i¯à¬O "ªm¤ô"¡]§N¤ô¥[¼ö 300 ¬íÅܦ¨ªm¤ô¡^¡C¦]¦¹¦b¤W­z½d¨Ò¤¤¡Adocument ´N¬O¤@­Ó JavaScript ªºª«¥ó¡A¥Nªí¦¹ºô­¶©Ò¦bªº¤å¥ó¡A¦Ó write() ´N¬O¤@­Ó¤èªk¡A¥i¥H±N¿é¤Jªº¦r¦ê¼g¨ì¤å¥ó¤º¡C

document ª«¥óÁÙ¦³¤@­Ó»P¦C¦L¬ÛÃöªº¤èªk¡Gwriteln()¡A¥¦©M write() ªº³Ì¤j®t§O¦b©ó writeln() ¦b¦C¦L§¹²¦«á·|´«¦C¡A¦ý write() ¤£·|¡C¨Ò¦p¦pªG³sÄò©I¥s document.write("Good") ©M document.write("Bye!")¡A¦bºô­¶·|§e²{³s¦b¤@°_ªº "GoodBye!"¡A¦ý¬O¦pªG³sÄò©I¥s document.writeln("Good") ©M document.writeln("Bye!")¡A«h¦bºô­¶·|§e²{¤¤¶¡¦³ªÅ®æªº "Good Bye!"¡A³o¬O¦]¬° "Good" ©M "Bye!" ¨Æ¹ê¤W¬O¼g¦b¤£¦Pªº¨â¦C¤W¡A¦bºô­¶±Æª©«á©Ò§e²{ªº®ÄªG¡A´N·|§Î¦¨¥ÑªÅ®æ¤À¶}ªº¨â­Ó­^¤å¦r¡C½d¨Ò¦p¤U¡G

Example¡]writeln01.htm¡^¡G

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

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

<body>
<h2 align=center>document.write() ©M document.writeln() ªº®t§O</h2>
<hr>
¨Ï¥Î document.write():
<script>document.write("Good"); document.write("Bye!");</script>
<br>
¨Ï¥Î document.writeln():
<script>document.writeln("Good"); document.writeln("Bye!");</script>

<hr>
</body>
</html>

¥Ñ¤W­z½d¨Ò¤]¥i¥H¬Ý¥X¡AJavaScript ¬O¦Û¥Ñ®æ¦¡¡]Free Format¡^ªº¡A¨C¤@¦Cµ{¦¡½X¥i¥H¶ë¤U¦n´X­Ó±Ô­z¡A¥u­n¨C¤@­Ó±Ô­z³£¦³¥[¤W¤@­Ó¤À¸¹¨Óªí¥Ü±Ô­zªºµ²§À¡C

­Y­n§e²{ JavaScript ¦L¥Xªº­ì©l®ÄªG¡A¦Ó¤£§Æ±æ¬Ý¨ìºô­¶±Æª©¤§«áªº®ÄªG¡A¥i¥H <pre> ©M </pre> ±N JavaScript ªºµ{¦¡½X«e«á¥]§¨¡A¨Ò¦p¡G

Example¡]writeln02.htm¡^¡G

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

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

<body>
<h2 align=center>§e²{ JavaScript ¦L¥Xªº­ì©l®ÄªG</h2>
<hr>

<pre>
¨Ï¥Î document.write():
<script>document.write("Good"); document.write("Bye!");</script>
¨Ï¥Î document.writeln():
<script>document.writeln("Good"); document.writeln("Bye!");</script>
¨Ï¥Î document.write() ¦A¥[¤W "\n":
<script>document.write("Good\n"); document.write("Bye!\n");</script>
</pre>

<hr>
</body>
</html>

Hint
¬°ÁY´î½g´T¡A«áÄòªºµ{¦¡½X¦Cªí¡A±N¤£¦AÅã¥Ü¼Ð·Çªº HTML ºô­¶ÀÉÀY»PÀɧÀ¡A¦Ó¥H¡u...¡v¨Ó¨ú¥N¡C

¥Ñ¤W­z½d¨Ò¥iª¾¡Adocument.write("...\n") ©M document.writeln("...") ±o¨ìªº®ÄªG¬O¤@¼Ëªº¡A¨ä¤¤ "\n" ¥Nªí´«¦C²Å¸¹¡AÃþ¦üªº²Å¸¹¥i¥H¾ã²z¦p¤U¡G

¯S®í¦r¤¸»¡©ú
\n´«¦C²Å¸¹¡]New Line¡^
\t©w¦ì²Å¸¹¡]Tab¡^
\rÂk¦ì²Å¸¹¡]Carriage Return¡^¡G±N´å¼Ð²¾¨ì¥Ø«e¦Cªº²Ä¤@­Ó¦ì¸m¡A¦L¥Xªº¤å¦r±N·|»\¹L¤§«eªº¤å¦r
\\´¡¤J¤@­Ó¤Ï±×½u¡]\¡^
\"´¡¤J¤@­ÓÂù¤Þ¸¹¡]"¡^
\'´¡¤J¤@­Ó³æ¤Þ¸¹¡]'¡^

Hint
¨Ï¥Î <pre> ©M </pre> ¨Ó¥]§¨ JavaScript ªºµ{¦¡½X¡A¥i¥H±oJavaScript ªº­ì©l¿é¥Xµ²ªG¡]¥¼¸gÂsÄý¾¹±Æª©¡^¡A «D±`¾A¥Î©óJavaScript µ{¦¡½Xªº°»¿ù¡C

¤U­±³o­Ó¨Ò¤l¡A·|¦bÂsÄý¾¹§e²{ 5 ­Ó¥Ñ¤pÅܤjªº "Hello World!"¡G

Example¡]hello02.htm¡^¡G

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

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

<body>
<h2 align=center>§Q¥Î JavaScript ¨Ó¦L¥X size ¥Ñ 1 ¨ì 5 ªº"Hello World!"</h2>
<hr>

<script>
// ¥Ñ for °j°é¨Ó²£¥Í 5 ­Ó¥Ñ¤pÅܤjªº  "Hello World!"
for (i=1; i<=5; i++)
	document.writeln("<font size=" + i + ">Hello World!</font><br>");
</script>

<hr>
</body>
</html>

¦b¤W¨Ò¤¤¡A§Ú­Ì§Q¥Î JavaScript ªº for °j°é¨Ó³v¦¸§ó§ï¦r¦êªº¤j¤p¡A¦]¦¹ÂsÄý¾¹¤W·|Åã¥Ü 5 ­Ó¥Ñ¤pÅܤjªº "Hello World!"¡C¡]¦³Ãö©ó for °j°é¡A§Ú­Ì·|¦b¤U¤@³¹¥J²Ó»¡©ú¡C¡^¥Ñ¥H¤W½d¨Ò§Ú­Ì¥iª`·N¨ì¤U¦C¨Æ¶µ¡G

§Ú­Ì«e­±´£¨ì¡A­Y­n±o¨ì¥¼¸gÂsÄý¾¹±Æª©«eªº JavaScript ¿é¥Xµ²ªG¡A¥i¥H¨Ï¥Î <pre> ©M </pre>¡A¦ý¬O¹ï©ó§t¦³ HTML ¼ÐÅÒªº¤å¦r¸ê®Æ¡A§Ú­Ì´N¥²¶·§ï¥Î <xmp> ©M </xmp>¡A¨Ò¦p¡A­Y­n¦L¥X«e¤@­Ó½d¨Ò¥¼¸gÂsÄý¾¹±Æª©«eªºµ²ªG¡A¥i¨£¤U¦C½d¨Ò¡G

Example¡]helloXmp01.htm¡^¡G

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

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

<body>
<h2 align=center>§Q¥Î &#60xmp&#62 ©M &#60/xmp&#62 ¨Ó¦L¥X¥¼¸gÂsÄý¾¹±Æª©ªºµ²ªG</h2>
<hr>

<script>
// ¥Ñ for °j°é¨Ó²£¥Í 5 ­Ó¥Ñ¤pÅܤjªº  "Hello World!"
document.write('<xmp>');
for (i=1; i<=5; i++)
	document.writeln("<font size=" + i + ">Hello World!</font><br>");
document.write('</xmp>');
</script>

<hr>
</body>
</html>

Hint
­Y±N <xmp> ¤Î </xmp> ¼g¦¨¸m©ó <script>...</script> ¤§¥~ªº HTML ¼ÐÅÒ¡A§A¥i¥H±o¨ì¤@¼Ëªºµ²ªG¶Ü¡H¬°¤°»ò¡H½Ð¸Õ¬Ý¬Ý¡I

´«¥y¸Ü»¡¡A§Ú­Ì¥i¥H¨Ï¥Î <pre> ©M <xmp> ¨ÓÆ[¹î¸g¥Ñ JavaScript ©ÎÂsÄý¾¹¸ÑĶ¤§«áªº¸ê®Æ¡A¸Ô²Ó¬yµ{¥i¨£¦¹¡uexample/HTML,JavaScript¸ÑĶ¤Î±Æª©¬yµ{¬yµ{.ppt¡v¡C

Example¡]HTML,JavaScript¸ÑĶ¤Î±Æª©¬yµ{¬yµ{.ppt¡^¡G

¦b¹L¥h Web ÂsÄý¾¹¸s¶¯¨Ã°_ªº®É¥N¡A¨Ã¤£¬O¨C¤@ºØÂsÄý¾¹³£¯à°÷¤ä´© JavaScript¡A¦]¦¹§Ú­Ì´N­n·Q¤@ºØ¿ìªk¨Ó¾A®É¦aÁôÂà JavaScript ªºµ{¦¡½X¡A¥HÁקK¤£»{±o JavaScript ªºÂsÄý¾¹±N JavaScript ªº­ì©l½X§e²{¦bºô­¶¤W¡C¨ä¤èªk´N¬O²V¦X¨Ï¥Î HTML ¤Î JavaScript ªºµù¸Ñ¡A¨Ò¦p¡G

<script language=javascript> <!-- JavaScript µ{¦¡½X ... //--> </script>
¦ý²{¦b¨â¤jÂsÄý¾¹³£¤ä´© JavaScript¡A©Ò¥H¨Ï¥Î³oºØ¡uÁôÂõ{¦¡½X¡vªº JavaScript ªºµ{¦¡¤w¸g¶V¨Ó¶V¤Ö¤F¡C¥H¥»¸`²Ä¤@­Ó "Hello World!" ªº¨Ò¤l¡A­Y¨Ï¥Î¡uÁôÂõ{¦¡½X¡vªº¤è¦¡¨Ó¼¶¼g¡A±o¨ìªººô­¶§e²{®ÄªG§¹¥þ¬Û¦P¡A¨ä­ì©lÀɮצp¤U¡G

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

<body>
<h2 align=center>¨Ï¥Îµù¸Ñ¨ÓÁôÂõ{¦¡½X¡A¨Ï¤£¤ä´© JavaScript ªºÂsÄý¾¹¤£·|²£¥Í¿ù»~°T®§</h2>
<hr>

<script language="javascript">
<!-- ¦pªGÂsø°¾¹µLªk¿ëÃÑJavaScriptµ{¦¡, «h±q¤U¦æ¶}©lÁôÂÃ
	str = "Hello World!";
	document.write(str);
// ÁôÂæܤW¦æ¬°¤î -->
</script>

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


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