7-1 ����Ψ��ݩʻP�ʽ�

§Ú­Ì¦b¤§«eªº³¹¸`¤w¸g²³æ¦a¤¶²Ð¹Lªí³æ¡A¥Ñ©óªí³æ¬O¨Ï¥ÎªÌ»P¦øªA¾¹¤§¶¡¤¬°Êªº¥D­n¾÷¨î¡A©Ò¥H§Ú­Ì·|¦b³o­Ó³¹¸`¥J²Ó¦a¤¶²Ðªí³æ¡A¤×¨ä¬Oªí³æ¤ºªº¦UºØ±±¨î¶µ¡]Controls¡^¡A¥H¤Î¨äÄÝ©Ê»P¹ïÀ³ªº©Ê½è¡C

ªí³æ¡]Forms¡^¬O¨Ï¥ÎªÌ¸g¥Ñºô­¶»P¦øªA¾¹¶i¦æ¤¬°Êªº³Ì±`¨£¤è¦¡¡C¤@¯ë¨Ó»¡¡A¨Ï¥ÎªÌ¥²¶·¸g¥Ñªí³æªº¶ñ¼g¡A¤~¯à±N«È¤áºÝªº¸ê®Æ°e¦^¦øªA¾¹ºÝ¡C¤@­Ó²³æªí³æªº­ì©l½X¦p¤U¡G

<form name=formName id=formId method=post action=example/formact.asp target=_blank> ¶Q©m¤j¦W¡G<input type=text name=UserName value="Test Input"> <input type=submit> <input type=reset> </form> ¦bºô­¶§e²{ªº®ÄªG¦p¤U¡G
¦b¤W¨Ò¤¤¡A¤@¥¹¨Ï¥ÎªÌ«ö¤U¡u°e¥X¬d¸ß¡vªº«ö¶s¡AÂsÄý¾¹´N±Nªí³æ¤¸¯Àªº­È¡]¨Ò¦p¤W­z½d¨Ò¤¤ªº¡uTest Input¡v¡^°e¦^¦øªA¾¹¡A¨Ã¦b¦øªA¾¹¥H¡uexample/formact.asp¡vªºµ{¦¡½X¨Ó³B²z¦¬¨ìªº¸ê°T¡A³Ì«á±N³B²zµ²ªG¦^¶Çµ¹ÂsÄý¾¹¡C¦³Ãö©ó¦øªA¾¹³B²zªí³æ¸ê®Æªº²Ó¸`¡A§Ú­Ì·|¦b¥»®Ñ²Ä¤G½g»P¦øªA¾¹¬ÛÃö³¹¸`¸Ì¦³§ó¸Ô²Óªº»¡©ú¡C

ªí³æ¼ÐÅÒ¦b HTML ­ì©l½X¤º¥i¥H¦³³\¦hÄÝ©Ê¡]Attributes¡^¡A¨Ò¦p name ¥Nªíªí³æªº¦WºÙ¡Amethod ¥NªíÂsÄý¾¹±Nªí³æ¸ê®Æ°e¦Ü¦øªA¾¹ªº¤è¦¡¡Aaction ¥Nªí¦b¦øªA¾¹ºÝ¡B­t³d³B²zªí³æ¸ê®Æªºµ{¦¡ÀÉ¡Atarget «h¥Nªí¦øªA¾¹¦^¶Ç¸ê®Æ«á¡A¥Î¤áºÝ¥Î©ó§e²{¦¹¸ê®Æªºµøµ¡¦WºÙ¡C¦ý¦b¨Ï¥Î JavaScript ©Î VBScript ®É¡Aªí³æ³Qµø¬°¤@­Óª«¥ó¡A¦¹ª«¥ó§Y¦³¦UºØ©Ê½è¡]Properties¡^©M¤èªk¡]Methods¡^¡Cªí³æ¼ÐÅÒªºÄÝ©Ê©Mªí³æª«¥óªº©Ê½è¡A´X¥G¦³µÛ¤@¹ï¤@ªº¹ïÀ³Ãö«Y¡A¦ý¥²¶·ª`·Nªº¬O¡AÄݩʬO¥Î©ó HTML¡A¦Ó©Ê½è«h¬O¥Î¦b JavaScript ©Î VBScript ¤§¤¤¡C¥H¤U±N°w¹ï±`¥Îªº¡uªí³æ¼ÐÅÒªºÄÝ©Ê¡v©M¡uªí³æª«¥óªº©Ê½è¡v¶i¦æ¦Cªí»¡©ú¡C

ªí³æ¼ÐÅÒªºÄݩʤλ¡©ú
ªí³æ¼ÐÅÒªºÄÝ©Ê»¡©ú¹ïÀ³ªºªí³æª«¥ó©Ê½è¤Î»¡©ú
name ªí³æªº¦WºÙ¡A¥i³Q JavaScript ©Î VBScript ¥Î¥H¦s¨úªí³æ¤Î¨ä¬ÛÃöª«¥ó¡C ¨Ò¦p¡A§Ú­Ì¥i¥Î document.formName ©Î¬O document.forms["formName"] ¨Ó¨ú±o¦¹ªí³æª«¥ó¡C
id ªí³æªº¦WºÙ¡A¥i³Q JavaScript ©Î VBScript ¥Î¥H¦s¨úªí³æ¤Î¨ä¬ÛÃöª«¥ó¡C ¨Ï¥Î id ®É¡A§Ú­Ì¥i¥H¤£¥²¸g¥Ñ DOM ªº¶¥¼h¦¡¬[ºc¨Ó¨ú±oªí³æª«¥ó¡A¨Ò¦p¡A§Ú­Ì¥i¥Hª½±µ¨Ï¥Î document.getElementById(formId) ©Î¬O document.all["formId"] ¨Ó¨ú±o¦¹ªí³æª«¥ó¡Cid ªº­È¦b¾ã­Óºô­¶¥²¶·¬O°ß¤@ªº¡A¥HÁקK©M¨ä¥Lª«¥ó²£¥Í½Ä¬ð¡C
target ¦øªA¾¹¦^¶Ç¸ê°T¥²¶·¥X²{ªº¦ì¸m¡A¥i¥H¬O¤@­Óµøµ¡ (Window)¡B®Ø¬[ (Frame)¡A©Î¬O _top¡B_parent¡B_self¡B_blank¡C­YµL¦¹ÄÝ©Ê¡A¡A«h¦^¶Çµ²ªG±N¥X²{©ó­ìµøµ¡¡C ¹ïÀ³ªº©Ê½è¬O target¡A¨Ò¦p¡G
action «ü©w¦øªA¾¹ºÝªº³B²zµ{¦¡¡C¦¹³B²zµ{¦¡¥i¥H¦ì©óºô¸ô¤Wªº¥ô¤@¥x¦øªA¾¹¡A¤]¥i¥H¨Ï¥Î mailto:xxx@xxx.xxx ªº¤è¦¡¨Ó±Nªí³æ¸ê°T¸g¥Ñ¹q¤l¶l¥ó±H¥X¡C ¹ïÀ³ªº©Ê½è¬O action¡A¨Ò¦p¡G
method «ü©w¸ê®Æ¶Ç°eªº¤è¦¡¡A¥i¦³¨âºØ¤è¦¡¡G
  • get: ªí³æ¸ê®Æ¸g¥Ñ QUERY_STRING ªºÀô¹ÒÅܼưe¦Ü¦øªA¾¹¡A³o¬O¹w³]ªº¤è¦¡¡A¦ý¶Ç°e¸ê®Æ¶q¦³­­¡A³q±`¥u­­©ó 1 KB ¥ª¥k¡C
  • post: ªí³æ¸ê®Æ¸g¥Ñ standard input ¶Ç°e¡A¸ê®Æªø«×Àx¦s©ó CONTENT_LENGTH ªºÀô¹ÒÅܼơA¶Ç°e¸ê®Æ¥i¤j©ó 1 MB¡C
¹ïÀ³ªº©Ê½è¬O method¡A¨Ò¦p¡G
enctype «ü©w MIME ªº½s½X¤è¦¡¨Ó¶Ç°e¸ê®Æ¡A¥i¥H¦³¨âºØ­È¡G"application/x-www-form-urlencoded" (¹w³]­È) ©Î "multipart/form-data"¡C ¹ïÀ³ªº©Ê½è¬O encoding¡A¨Ò¦p¡G
onSubmit JavaScript ©Î VBScript ªº¨Æ¥ó³B²z¾¹¡A­Y¦^¶Ç­È¬° false¡A«hªí³æ±N¤£·|³Q°e¥X¡C¦¹Äݩʳq±`¥Î¨ÓÀˬd¨Ï¥ÎªÌ©Ò¶ñ¤Jªºªí³æ¸ê®Æ¬O§_¥¿½T¡A­Y¤£¥¿½T¡A´N¤£±Nªí³æ¸ê®Æ°e¨ì¦øªA¾¹¡C ¹ïÀ³ªº©Ê½è¬O onSubmit¡C

¦¹¥~¡Aªí³æª«¥ó¤]¦³¤@¨Ç©Ê½è¡A¬OµLªk©Mªí³æ¼ÐÅÒ¹ïÀ³ªº¡A¨Ò¦p elements¡]¥Ñªí³æ¤¸¯À©Ò§Î¦¨ªº°}¦C¡^©M Length¡]ªí³æ¤¸¯Àªº­Ó¼Æ¡^µ¥¡A¥H¤U§Ú­Ì¦C¥X¤@­Óªí³æª«¥óªº©Ò¦³©Ê½è¡AÅý¤j®a°Ñ¦Ò¡G

Example¡]formProp01.htm¡^¡G

¨ä­ì©l½X¬°¡G

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

<body>
<h2 align=center>ªí³æªº©Ê½è¦Cªí</h2>
<hr>
<form name=formName id=formId method=post action=formact.asp target=_blank>
	¶Q©m¤j¦W¡G<input type=text name=UserName value="Test Input">
	<input type=submit> <input type=reset>
</form>
<hr>

<script src="listProp.js"></script>
¥H¤U¨Ï¥Î listProp(formId, "formId") ¨Ó¦C¥X¤W­zªí³æªº©Ò¦³©Ê½è¡C
§A¤]¥i¥H¨Ï¥Î listProp(document.formName, "document.formName") ¨Ó¹F¨ì¦P¼Ëªº¥\¯à³á¡C
<p><h3>"document.formName" ªº©Ê½è¦Cªí¡G</h3>
<p><script>listProp(formId, "formId")</script>

<hr>
</body>
</html>

·íµM¡AÀHµÛÂsÄý¾¹ªº§ó·s¡Aªí³æªº©Ê½è¤]·|¶V¨Ó¶V¦h¡A¨ä¤¤³Ì­«­nªº©Ê½è·íµM¬O elements¡A³o´N¬Oªí³æ¤¸¯À¡]©ÎºÙ±±¨î¶µ¡^©Ò§Î¦¨ªº°}¦C¡A±N·|¦b¤U¤@¸`¸Ô­z¡C

¤@­¶ HTML ¤¤¥i¥H¥]§t¼Æ­Óªí³æ¡A¦ý³Ì¦n¨ú¥Î¤£¦Pªº¦WºÙ¡A¥H¨Ï JavaScript ©Î VBScript ¯à®Ú¾Ú¦WºÙ¨Ó¦s¨ú¤£¦Pªí³æ¡C¦ý¦³®É­Ô¬°¤Fµ{¦¡½X²¼ä¡A¤]¥i¥H¤£³]©wªí³æªº name ©Î id ÄÝ©Ê¡A¦¹®É¥i¥H¨Ï¥Î document.forms[0], document.forms[1], document.forms[2] µ¥µ¥¨Ó¨ú±o²Ä¢¯¡B¢°¡B¢±­Óªí³æ¡A¨Ì¦¹Ãþ±À¡C

¦¹¥~¡A¦b¨Ï¥Îªí³æª«¥ó®É¡A¦Ò¼{¨ìªí³æ¥i¯à¦Ü©ó®Ø¬[¡]Frames¡^¤§¤¤¡A¦]¦¹¨ú¥Î¤@­Ó©Ê½èªº§¹¾ã¤èªk¬°¡G

window.parent.frames[0].document.forms[0].property
¦ý¬O®Ø¬[ªº¨Ï¥Î¤]¬O¶V¨Ó¶V¤Ö¡A©Ò¥H´N¥i¥H¤£¥²³o»ò³Â·Ð¡C
JavaScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©óºô­¶¥Î¤áºÝ