6-1 DOM ���ʽ�

·íÂsÄý¾¹Åª¤J¤@­¶ºô­¶®É¡A´N·|®Ú¾Ú¦¹ºô­¶ªº¤º®e¨Ó«Ø¥ß¬ÛÃöªº¤å¥óª«¥ó¼Ò«¬¡]Document Object Model¡A²ºÙ DOM¡^¡A³o¬O¤@­Ó¶¥¼h¦¡ªºª«¥ó¼Ò«¬¡A¥]§t¤Fºô­¶ªº¦UºØª«¥ó¡A§Ú­Ì»Ý­nÁA¸Ñ³o¨Çª«¥óªº©Ê½è©M¤èªk¡A¤~¯à²£¥Í°ÊºAªººô­¶¡A¥R¤À§Q¥Î°ÊºA HTML¡]Dynamical HTML¡A²ºÙ DHTML¡^ªº¦UºØ¥\¯à¡C

Hint
³o¨Çª«¥óªº©w¸q¬O®Ú¾Ú WWW Consortium ªº¼Ð·Ç¨Ó¨î­q¡A¬ÛÃö²Ó¸`¥i¥H°Ñ¦Ò¨äºô¯¸¡Ghttp://www.w3c.org¡C

¦b¤å¥óª«¥ó¼Ò«¬¤¤¡A©Ò¦³ªºª«¥ó¤§¶¡ªºÃö«Y¡A¬O¥Ñ¤@­Ó¶¥¼h¦¡ªº¾ðª¬¬[ºc¨Ó§e²{¡A½Ð¨£¤U¹Ï¡G

¥Ñ¤W¹Ï¥i¥H¬Ý¥X¡Awindow ª«¥ó¬O©Ò¦³ª«¥óªº©l¯ª¡C¦Ó¥Ñ¨C­Óª«¥óªº¤À¤ä¦h¹è¡A´N¥i¥H¤j·§¬Ý¥X¦¹ª«¥óªº­«­n©Ê¡A¨Ò¦p¡A window ¨ä¤U³Ì­«­nªºª«¥ó¬O document¡A¦Ó document ¨ä¤U³Ì­«­nªºª«¥ó¬O form¡C ³o¨Çª«¥ó¦U¦³¤£¦Pªº©Ê½è (Properties) ¤Î¤èªk (Methods)¡AJavaScript ¥i§Q¥Î³o¨Ç©Ê½è¤Î¤èªk¨Ó«Ø¥ßºô­¶ªº¤¬°Ê©Ê¡C

­º¥ý§Ú­Ì¥²¶·ª¾¹D¦p¦ó¨ú±oª«¥óªº©Ê½è¡A¨Ã¶i¦Ó§ïÅܳo¨Ç©Ê½è¡A¤~¯à²£¥Í°ÊºAºô­¶¡C±ý¦s¨úª«¥óªº©Ê½è¡A¦³¤U¦C¤TºØ¤èªk¡G

  1. ¥Î©Ê½è¦WºÙ¨Ó¦s¨úª«¥óªº©Ê½è¡]³o¬O³Ì±`¥Î¨ìªº¤èªk¡^¡G
    objectName.propertyName

  2. ¥Î©Ê½è¦WºÙ¨Ó¦s¨úª«¥óªº©Ê½è¡]¦¹ºØ¤èªk¦Pµ¥©ó«e¤@ºØ¤èªk¡A¨ä¦n³B¬O¡G¥i±N©Ê½è¦WºÙ¥H¦r¦êÅܼƶǤJ¡^¡G
    objectName["propertyName"]

  3. ¥Î¯Á¤Þ¨Ó¦s¨úª«¥óªº©Ê½è¡]¤ñ¸û¤Ö¥Î¡^¡G
    objectName[index]
­º¥ý¡A§Ú­Ì¥ý¬Ý¬Ý window ª«¥ó´X­Ó±`¥Îªº©Ê½è¡A§Q¥Î³o¨Ç©Ê½è¡A§Ú­Ì¥i¥H¥ß¨è§ì¥X¥Ø«eºô­¶ªººô§}¡A¥H¤Îµøµ¡ªº®y¼Ðµ¥¸ê°T¡A½d¨Ò¦p¤U¡G

Example¡]winProp02.htm¡^¡G

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

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

<body>
<h2 align=center>window ª«¥óªº´X­Ó°ò¥»©Ê½è</h2>
<hr>

¥»­¶ªººô§}¡]window.location¡^¡G<script>document.write(window.location);</script><br>
¥»µøµ¡¡]¥iÅã¥Üºô­¶½d³ò¡^¥ª¤W¨¤ªº X-®y¼Ð¡]window.screenLeft¡^¡G<script>document.write(window.screenLeft);</script><br>
¥»µøµ¡¡]¥iÅã¥Üºô­¶½d³ò¡^¥ª¤W¨¤ªº Y-®y¼Ð¡]window.screenTop¡^¡G<script>document.write(window.screenTop);</script><br>

<hr>
</body>
</html>

§A¥i¥H²¾°Ê¥»½d¨Òªºµøµ¡¡AµM«á¦b§ó·s¦¹ºô­¶¡A´N·|¬Ý¨ì¤£¦Pªº X ©M Y ®y¼Ð­È¡C

Hint
¦b¤@¯ëªºµøµ¡¨t²Î¡A¥ª¤W¨¤¬°­ìÂI¡A¦V¥k¬° X ®y¼Ðªº¥¿¦V¡A¦V¤U¬° Y ®y¼Ðªº¥¿¦V¡C

¤U¤@­Ó½d¨Ò¡A§Ú­Ì»¡©ú¦p¦ó¸g¥Ñ window ª«¥óªº©Ê½è¨Ó­×§ïµøµ¡ªºª¬ºA¦C¡]Status Line¡^¡C¤@¯ë¦Ó¨¥¡Aª¬ºA¦C¬O¦bÂsÄý¾¹µøµ¡ªº³Ì¤U¤è¡A¦b¹w³]ªº±¡ªp¤U¡A·í§A±N·Æ¹«¸m©óºô­¶¤¤ªº¤@­Ó³sµ²®É¡AÂsÄý¾¹´N·|¦bª¬ºA¦C¨q¥X¦¹³sµ²ªººô§}¡C±ý§ïÅÜÂsÄý¾¹ª¬ºA¦Cªº¤å¦r¡A¥i±N¤å¦r«ü©w¦Ü¤U¦C¨â­Ó©Ê½è¡G

½Ð¨£¤U¦C½d¨Ò¡G

Example¡]winStatus01.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A§Ú­Ì±NÂsÄý¾¹µøµ¡ªº¹w³]ª¬ºA¦C§ï¦¨¡u³o¬O§Úªº¹w³]ª¬ºA°T®§¡v¡A¦ý¬O·í¨Ï¥ÎªÌ±N·Æ¹«©ñ¦b¡u²MµØ¤j¾Ç¡v®É¡Aª¬ºA¦Cªº°T®§«h·|§ï¬°¡u²MµØ¤j¾Çªº­º­¶¡v¡A¦Ó¤£·|¹³¤@¯ëÂsÄý¾¹¥X²{²M¤j­º­¶ªººô§}¡A³o¬O¦]¬°§Ú­Ì¨Ï¥Î onMouseOver ¨Æ¥ó¡]·í·Æ¹«¸m©ó³sµ²®É¡^¨ÓIJµo¤@¬q JavaScript ªºµ{¦¡½X¡A¨Ã¶i¦Ó§ïÅÜ window.status¡C¯S§O­nª`·Nªº¬O¡G¦¹¬qµ{¦¡½X¥²¶·¦^¶Ç true¡A§_«h window.status ªº§ïÅܱN¤£·|µo¥Í¡A½Ð¨£¤W­z½d¨Òªº­ì©lÀÉ¡G

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

<body>
<h2 align=center>¦p¦ó§ïÅÜ window ª«¥óªºª¬ºA¦C</h2>
<hr>

<script>window.defaultStatus="³o¬O§Úªº¹w³]ª¬ºA°T®§";</script>

<a href="http://www.nthu.edu.tw" onMouseOver="window.status='²MµØ¤j¾Çªº­º­¶'; return true">²M¤j­º­¶</a><br>
<a href="http://www.nctu.edu.tw" onMouseOver="window.status='¥æ³q¤j¾Çªº­º­¶'; return true">¥æ¤j­º­¶</a><br>
<a href="http://www.ntu.edu.tw" onMouseOver="window.status='¥xÆW¤j¾Çªº­º­¶'; return true">¥x¤j­º­¶</a><br>

<hr>
</body>
</html>

Hint
¦³¨Ç¥­¥x¡]¨Ò¦p XP¡^¤Wªº IE ÂsÄý¾¹¡A¦b¹w³]ªº±¡ªp¤U¬O¤£·|Åã¥Üª¬ºA¦C¡C¦b³oºØ±¡ªp¤U¡A§A¥i¥H¨Ï¥ÎÂsÄý¾¹ªº¤U©Ô¦¡¿ï³æ¡uÀ˵ø/ª¬ºA¦C¡v¨Ó³]©wÅã¥Üª¬ºA¦C¡C

¦b window ª«¥ó¤§¤U¡A³Ì­«­nªºª«¥ó´N¬O document¡A¦³Ãö©ó document ª«¥óªº´X­Ó±`¥Î¨ìªº©Ê½è¡A½Ð¨£¤U¦C½d¨Ò¡G

Example¡]docProp02.htm¡^¡G

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

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

<body>
<h2 align=center>document ª«¥óªº­«­n©Ê½è</h2>
<hr>


<script>
document.write("document.location = <font color=red>"+document.location+"</font>¡]¥»­¶ªººô§}¡^<br>");
document.write("document.URL = <font color=red>"+document.URL+"</font>¡]¥»­¶ªººô§}¡^<br>");
document.write("document.referrer = <font color=red>"+document.referrer+"</font>¡]³sµ²¨ì¥»­¶ªº«e¤@­¶ºô§}¡^<br>");
document.write("document.lastModified = <font color=red>"+document.lastModified+"</font>¡]¥»­¶ªº³Ì«á­×§ï®É¶¡¡^<br>");
document.write("document.fileModifiedDate = <font color=red>"+document.fileModifiedDate+"</font>¡]¥»­¶ªº³Ì«á­×§ï®É¶¡¡^<br>");
document.write("document.fileUpdatedDate = <font color=red>"+document.fileUpdatedDate+"</font>¡]Àɮ׭קï¤é´Á¡^<br>");
document.write("document.fileCreatedDate = <font color=red>"+document.fileCreatedDate+"</font>¡]Àɮײ£¥Í¤é´Á¡^<br>");
document.write("document.fileSize = <font color=red>"+document.fileSize+"</font>¡]Àɮפj¤p¡^<br>");
document.write("document.bgColor = <font color=red>"+document.bgColor+"</font>¡]ºô­¶­I´ºÃC¦â¡^<br>");
document.write("document.fgColor = <font color=red>"+document.fgColor+"</font>¡]ºô­¶«e´ºÃC¦â¡^<br>");
document.write("document.linkColor = <font color=red>"+document.linkColor+"</font>¡]¤å¦r³sµ²ÃC¦â¡^<br>");
document.write("document.alinkColor = <font color=red>"+document.alinkColor+"</font>¡]ÂI¿ï¤¤ªº¤å¦r³sµ²ÃC¦â¡^<br>");
document.write("document.vlinkColor = <font color=red>"+document.vlinkColor+"</font>¡]ÂI¿ï«áªº¤å¦r³sµ²ÃC¦â¡^<br>");
document.write("document.defaultCharset = <font color=red>"+document.defaultCharset+"</font>¡]¹w³]ªº¦r¤¸¶°¡^<br>");
document.write("document.cookie = <font color=red>"+document.cookie+"</font>¡]¤p»æ°®ªº¦r¦ê­È¡^<br>");
document.write("document.protocol = <font color=red>"+document.protocol+"</font>¡]¨Ï¥Îªº¶Ç¿é¨ó©w¡^<br>");
document.write("document.mimeType = <font color=red>"+document.mimeType+"</font>¡]MIME ¸ê®Æ®æ¦¡¡^<br>");
document.write("document.security = <font color=red>"+document.security+"</font>¡]¦w¥þ¾ÌÃÒ¸ê°T¡^<br>");
</script>

<hr>
</body>
</html>

¤W­z½d¨Ò¤¤¡A³Ì±`¥Îªº©Ê½è´N¬O document.lastModified¡A¥i¥H¶Ç¦^ºô­¶³Ì«á­×§ï®É¶¡¡AÅý¨ä¥L¨Ï¥ÎªÌª¾¹D¦¹ºô­¶ªº¦³®Ä©Ê¡C

¦¹¥~¡A¤@­Ó±`¨£ªºÀ³¥Î¡A´N¬O­n¨¾¤î¨ä¥Lºô­¶ªºµs³s¡A©Ò¨Ï¥Îªº document ªº©Ê½è¬O¡G

½d¨Ò¦p¤U¡G

Example¡]referrer01master.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A¦pªG§Ú­Ìª½±µ±q¡u¥Dºô­¶¡vÂI¿ï¡u³Q«OÅ@ªººô­¶¡v¡A«h¥i¥Hª½±µÅã¥Ü¡u³Q«OÅ@ªººô­¶¡v¡C¦ý¬O¦pªG§Ú­Ìª½±µ±N¡u³Q«OÅ@ªººô­¶¡vªººô§}¶K¦bÂsÄý¾¹ªººô§}¦C¡]©ÎÂI¿ï¨ä¥¦ºô­¶¤¤§t¦³¡u³Q«OÅ@ªººô­¶¡vªº³sµ²¡^¡AJavaScript ¥i¥Ñ document.referrer °»´ú³oºØ¡uµs³s¡vªº±¡ªp¡A¦]¦¹¤£·|Åã¥Ü¡u³Q«OÅ@ªººô­¶¡v¡A¦Ó·|ª½±µÂà§}¨ì¡u¥Dºô­¶¡v¡C±Ä¥Î³oºØ¾÷¨î¡A¥i¥H½T«O¦Û¤vªº©³¼hºô­¶¤º®e¤£·|³Q¡uµs³s¡v¡A¦Ó¤@©w­n±q¥Dºô­¶¶i¤J¡C¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

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

<body>
<h2 align=center>¨Ï¥Î document.referrer ¥H¨¾µs³s¡G¥Dºô­¶</h2>
<hr>

¦¹­¶¬O¥Dºô­¶¡A¥Ñ¦¹¥i¥H¦Xªk³s¨ì<a href="referrer01slave.htm">³Q«OÅ@ªººô­¶</a>

<hr>
</body>
</html>

³Q«OÅ@¤§ºô­¶ªº­ì©lÀɦp¤U¡G

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

<body>
<h2 align=center>¨Ï¥Î document.referrer ¥H¨¾µs³s¡G³Q«OÅ@ªººô­¶</h2>
<hr>

<script>
if (document.referrer.indexOf("referrer01master.htm")==-1){
	// ­­¨î¦¹­¶¥²¶·¬O¥Ñ"referrer01master.htm"ªº¶W³sµ²³s¹L¨Ó
	alert("³sµ²¥¢±Ñ¡I\ndocument.referrer="+document.referrer);
	alert("½Ð±q¥Dºô¯¸¶i¤J¥»­¶");
	document.location = "referrer01master.htm";	// Âà§}¦Ü¥Dºô­¶
} else {
	alert("³sµ²¦¨¥\¡I\ndocument.referrer="+document.referrer);
}
</script>

³o¬O³Q«OÅ@ºô­¶ªº¤º®e¡C

<hr>
</body>
</html>

¦pªG§Ú­Ì±N³Q«OÅ@¤§ºô­¶ºô§}ª½±µ¶K¨ìÂsÄý¾¹ªººô§}¦C¡AÂsÄý¾¹·|¸g¥Ñ document.referrer ¨Ó§PÂ_¬O§_¦X®æ¡A¨Ã¶i¦æ¥²­n¤§Âà§}¡C

­Y­n´ú¸Õ«È¤áºÝ©Ò¥ÎªºÂsÄý¾¹¡A¥i¥H¨Ï¥Î navigator ª«¥óªº¦UºØ©Ê½è¡A½d¨Ò¦p¤U¡G

Example¡]navProp02.htm¡^¡G

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

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

<body>
<h2 align=center>navigator ª«¥óªº´X­Ó­«­n©Ê½è</h2>
<hr>


<script>
document.write("navigator.appName = "+navigator.appName+"¡]ÂsÄý¾¹¦WºÙ¡^<br>");
document.write("navigator.appVersion = "+navigator.appVersion+"¡]ÂsÄý¾¹¥D­nª©¥»¡^<br>");
document.write("navigator.appminorVersion = "+navigator.appMinorVersion+"¡]ÂsÄý¾¹¦¸­nª©¥»¡^<br>");
document.write("navigator.appCodeName = "+navigator.appCodeName+"¡]ÂsÄý¾¹¥N½X¡^<br>");
document.write("navigator.cpuClass = "+navigator.cpuClass+"¡]CPU Ãþ§O¡^<br>");
document.write("navigator.platform = "+navigator.platform+"¡]§@·~¨t²Î¥­¥x¡^<br>");
document.write("navigator.systemLanguage = "+navigator.systemLanguage+"¡]ÂsÄý¾¹¹w³]»y¨¥¡^<br>");
document.write("navigator.userLanguage = "+navigator.userLanguage+"¡]¨Ï¥ÎªÌ¹w³]»y¨¥¡^<br>");
document.write("navigator.cookieEnabled = "+navigator.cookieEnabled+"¡]¬O§_¤¹³\¨Ï¥Î¤p»æ°®¡^<br>");
</script>

<hr>
</body>
</html>

´«¥y¸Ü»¡¡A§Ú­Ì¥u­n¨Ï¥Î navigator ª«¥óªº¦UºØ©Ê½è¡A´N¥i¥Hª¾¹D¨Ï¥ÎªÌªºÂsÄý¾¹Ãþ§O¡Bª©¥»¡BCPU Ãþ§O¡B¥­¥x¡B¬O§_¤ä´©¤p»æ°®¤§Ãþªº¸ê°T¡A¹ï©ó§Ú­Ì¼¶¼g¸ó¥­¥xªº JavaScript µ{¦¡½X«D±`¦³¥Î¡C

¬Ý¤F¤W­±ªº½d¨Ò¡A¦U¦ìŪªÌ¤@©w¦³¤@­ÓºÃ°Ý¡G¤@­Óª«¥ó¨ì©³¦³¤°»ò©Ê½è©O¡HÁÙ¦³³o¨Ç©Ê½è¥Nªí¤°»ò·N¸q©O¡H¨Æ¹ê¤W¡AÀHµÛÂsÄý¾¹ªººt¶i¡A¨C¤@­Óª«¥ó©Ò¥]§tªº©Ê½è¬O¶V¨Ó¶V¦h¡A¦]¦¹­Y¯àª½±µ¥Ñ JavaScript ¨Ó¦C¥Xºô­¶¤å¥ó¤¤ªºª«¥ó©Ò¨ã¦³ªº©Ê½è¡A¨º´N¦A¦n¤£¹L¤F¡I§Ú­Ì³o¸Ì¦³­Ó JavaScript ªº¨ç¼Æ listProp(obj, objName)¡A¥i¥H¦C¥X¤@­Óª«¥óªº©Ò¦³©Ê½è¡A¨ä­ì©l½X¦p¤U¡G

­ì©lÀÉ¡]listProp.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¦C¦Lª«¥ó©Ê½è
function listProp(obj, objName) {
	for (var i in obj)
		document.writeln(objName+".<font color=red>"+i+"</font> = <font color=green>"+obj[i]+"</font><br>");
}

¦b¤W­zµ{¦¡½X¤¤¡Aobj ¬O¶Ç¤J¨ç¼Æªºª«¥óÅܼơAobjName «h¬Oª«¥ó¦WºÙ¡A§½³¡ÅÜ¼Æ i «h·|¨Ì¦¸µ¥©óª«¥óªº¨C¤@­Ó©Ê½è¦WºÙ¡Aobj[i] «h¬O¹ïÀ³©Ê½èªº­È¡A§Ú­Ì¦A¥Î document.writeln ªº¤èªk¨Ó±N³o¨Ç¸ê°T¦L¥X¦Üºô­¶¡C

Á|¨Ò¨Ó»¡¡A­Y­n¦C¥X document ª«¥ó©Ò¨ã¦³ªº©Ê½è¡A¥i§Q¥Î listProp.js ªº¨ç¼Æ¡A½d¨Ò¦p¤U¡G

Example¡]docProp01.htm¡^¡G

¤W­z½d¨Òªº§¹¾ã­ì©lÀɮצp¤U¡G

­ì©lÀÉ¡]docProp01.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<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">²M¤j­º­¶</a><br>
<a href="http://www.nctu.edu.tw">¥æ¤j­º­¶</a><br>
<a href="http://www.ntu.edu.tw">¥x¤j­º­¶</a>
<hr>

<script src="listProp.js"></script>
<p><h3>"document" ªº©Ê½è¦Cªí¡G</h3>
<p><script>listProp(document, "document")</script>

<hr>
</body>
</html>

¥Ñ¦¹½d¨Ò¥i¨£ document ª«¥ó¦³³\¦h©Ê½è¡A³o¨Ç©Ê½è³£¥i¥Ñ¤W­z¤èªk³v¤@¦C¥X¡C­Y¥X²{ªº©Ê½è¬O [object]¡A¥Nªí¦¹©Ê½è¬O¥t¤@­Óª«¥ó¡A¦]¦¹§Ú­Ì¥i¥H¦A¦¸¦C¥X¦¹ª«¥óªº©Ê½è¡A¨Ò¦p¡Adocument.links ¬O¥t¤@­Óª«¥ó¡A¥Nªí¦¹¤å¥ó¤¤©Ò§tªº³sµ²¡A¦]¦¹§Ú­Ì¥i¥H¦A¦¸§Q¥Î lispProp.js¡A¦L¥X document.links ªº©Ò¦³©Ê½è¡A¦p¤U¡G

Example¡]docLinkProp01.htm¡^¡G

¤W­z½d¨Òªº§¹¾ã­ì©lÀɮצp¤U¡G

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

<body>
<h2 align=center>"document.links" ªº©Ê½è¦Cªí</h2>
<hr>
<a target=_blank href="http://www.nthu.edu.tw">²M¤j­º­¶</a><br>
<a target=_blank href="http://www.nctu.edu.tw">¥æ¤j­º­¶</a><br>
<a target=_blank href="http://www.ntu.edu.tw">¥x¤j­º­¶</a>
<hr>

<script src="listProp.js"></script>
<p><h3>"document.links" ªº©Ê½è¦Cªí¡G</h3>
<p><script>listProp(document.links, "document.links")</script>

<hr>
</body>
</html>

¦P²z¡A§Ú­Ì¥i¥H¹ï window ©Î¬O navigator ª«¥óªº©Ê½è¶i¦æ§¹¾ãªº¦Cªí¡A¬ÛÃö½d¨Ò¥i¨£¥»®Ñ¤§½d¨Ò¥úºÐ¡G

§Ú­Ì¤]¥i¥H¨Ï¥Î DOM ªº¦UºØª«¥ó»P¤èªk¨Ó¥ß§Y¤Á´«­µ¼Ö¡]¥]§t MIDI¡BMP3 ©M wma ­µ¼Ö¡^»P¹Ï¤ù¡A½Ð¨£¤U¦C½d¨Ò¡G

Example¡]bgSound01.htm¡^¡G

§A¥i¥HÂI¿ï¡u´«­I´º¹Ï¤ù¡v¨Ó¥Ñ¶Ã¼Æ¿ï¨ú­I´º¡A¤]¥i¥HÂI¿ï¡u´«­I´º­µ¼Ö¡v¨Ó¥Ñ¶Ã¼Æ¿ï¨ú­I´º­µ¼Ö¡C¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

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

<body>
<h2 align=center>°ÊºA¤Á´«­µ¼Ö©M­I´º</h2>
<hr>

<script>
function changeBackground() {
	var imgURL = ["bg1.gif", "bg2.gif", "bg3.gif", "bg4.jpg", "bg5.gif"];
	document.body.background = "image/" + imgURL[Math.floor(Math.random()*5)];
}
function changeMusic() {
	var soundURL = ["tomorrow.mid", "¦pªG¶³ª¾¹D.mid", "­ì¨Ó§A¤°»ò³£¤£·Q­n.mid", "Áx¤p°­.mid", "Å¥®ü.mid"];
	myMusic.src = "music/" + soundURL[Math.floor(Math.random()*5)];
}
</script>

<bgsound id="myMusic" src="" loop="infinite">
<form>
<center>
<input type="button" value="´«­I´º¹Ï¤ù" onClick="changeBackground()">
<input type="button" value="´«­I´º­µ¼Ö" onClick="changeMusic()">
</center>
</form>

</body>
</html>

¥»½d¨Òªº¬ÛÃö§Þ³N­«ÂI¡A»¡©ú¦p¤U¡G

¤@¯ë¦Ó¨¥¡A¨C¤@­Ó HTML ªº¼ÐÅÒ´N¬O¤@­Óª«¥ó¡A§Ú­Ì¥i¥H¨Ï¥Î id ¼ÐÅÒ¨Ó¦s¨ú¦¹ª«¥ó¡A¨Ò¦p³]©w id=idValue¡C¤@¯ë¦Ó¨¥¡A¦pªG¦¹¼ÐÅÒ¬O¦b document ªº¤U¤@¼h¡]©Î¬O¦ì©ó <body> ¤Î </body> ¤º¥B¤£³Q¨ä¥L¼ÐÅÒ©Ò¥]§¨¡^¡A«h§Ú­Ì¥i¥Hª½±µ¨Ï¥Î¦¹ idValue ¨Ó¦s¨ú¦¹ª«¥ó¡A¨Ò¦p¤W­z½d¨Òªº myMusic.src¡C¦ý¬O¡A¦pªG¼ÐÅÒ¬O¦b¼h¼h DOM ¤§¤U¡]¨Ò¦pªí³æ¤ºªº¤å¦rÄæ¦ì¡^¡A¨º»òª½±µ¨Ï¥Î idValue ¬OµL®Äªº¡A¦¹®É¥u­n idValue ¦b¾ã­Óºô­¶¬O°ß¤@ªº¡A§Ú­Ì¥i¥H¨Ï¥Î¨âºØ¤èªk¨Ó¨ú±o¦¹ª«¥ó¡G ·íµM¡A¹ï©ó¨C¤@­Ó¼ÐÅÒ¡A§Ú­ÌÁÙ¬O¥i¥H¨Ï¥Î name ¼ÐÅÒ¨Ó«ü©w¦¹ª«¥ó¡A¦ý¨ú¥Î¤ñ¸û³Â·Ð¡A¥²¶·±q document ¶}©l§ì¨ú¡A¨Ò¦p¦pªG¤@­Ó¤å¦rÄæ¦ì¡]name=myText¡^¦ì©ó¤@­Óªí³æ¡]name=myForm¡^¡A¨º»ò¦¹¤å¦rÄæ¦ì©Ò¹ïÀ³ªºª«¥ó´N¬O document.myForm.myText.
JavaScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©óºô­¶¥Î¤áºÝ