ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[±Ð¾Ç] (±Ð¾Ç²Ä4½g)JavaScript ±ø¥ó§PÂ_±Ô­zif

[±Ð¾Ç] (±Ð¾Ç²Ä4½g)JavaScript ±ø¥ó§PÂ_±Ô­zif

±ø¥ó§PÂ_±Ô­zif
if§PÂ_±Ô­z¬O§Ú­Ì³Ì±`¥Î¨ÓÅýµ{¦¡ÂàÅsªº§PÂ_±Ô­z¡A¥¦ªº³q¥Î®æ¦¡¬O¡G
  1. If  (±ø¥ó¦¡)
  2. {
  3.      µ{¦¡±Ô­z
  4. }
½Æ»s¥N½X
¥¦ªº·N¸q¬O¡G¦pªG¡y±ø¥ó¦¡¡z¦¨¥ß¡]µû¦ô­È¬°True¡^¡A´N°õ¦æ¤j¬A¸¹¡y¡a¡b¡z¤§¶¡ªºµ{¦¡±Ô­z¡A¤£µMªº¸Ü´N¸õ¹L¤j¬A¸¹¡y¡a¡b¡z¤§¶¡ªºµ{¦¡±Ô­z¡AÄ~Äò°õ¦æ¤j¬A¸¹¡y¡a¡b¡z¤§«áªºµ{¦¡±Ô­z¡C

¹ê°µ¾Ç²ß
³]­p¤@JavaScriptµ{¦¡¡A±NÂsÄýªÌ¶}©lÂsÄýºô­¶ªº®É¶¡Åã¥Ü¦bºô­¶¤¤¡A­YÂsÄý®É¶¡¤¶©ó¦­¤W¢¸ÂI¦Ü¤U¤È¢´ÂI®É¡A«h¦P®É¦bºô­¶¤¤Åã¥Ü¡¨²{¦b¬O¤W¯Z®É¶¡¡¨¡G
  1. <Script LANGUAGE="JavaScript">
  2. begintime = new Date();
  3. beginhours=begintime.getHours();
  4. beginminutes=begintime.getMinutes();
  5. beginseconds=begintime.getSeconds();
  6. document.write(beginhours+"®É"+beginminutes+"¤À"+beginseconds+"¬í<br>");
  7. if  (beginhours>=9  && beginhours<=17)
  8. {
  9. document.write("²{¦b¬O¤W¯Z®É¶¡");
  10. }
  11. </Script>
½Æ»s¥N½X
­ì©l½X¤¤ªº¡y>=¡z²Å¸¹¤Î¡y<=¡z²Å¸¹¬°¤ñ¸û¹Bºâ¤l¡y¤j©óµ¥©ó¡z»P¡y¤p©óµ¥©ó¡z¡A¥Î¨Ó¤ñ¸ûÅܼÆbeginhours©M¼Æ­È9»P15ªº¤j¤p¡A¦Ó¡y&&¡z²Å¸¹«h¬°ÅÞ¿è¹Bºâ¤l¬O¡y¨Ã¥B¡zªº·N«ä¡A¦pªGÅܼÆbeginhours¤j©óµ¥©ó9¨Ã¥B¤p©óµ¥©ó15«h¦^¶ÇTrue­È¡A¤j¬A¸¹¡y¡a¡b¡z¤§¶¡ªºµ{¦¡±Ô­z´N·|³Q°õ¦æ¡A¤Ï¤§¡A¦b¤j¬A¸¹¡y¡a¡b¡z¤§¶¡ªºµ{¦¡±Ô­z´N¤£·|³Q°õ¦æ¡C


¹ê°µ¾Ç²ß
¤§«e§Ú­Ì¤w¸g¤¶²Ð¹L¤é´Áª«¥óDate()¡A¦P®É¤]§iª¾¤FÂ^¨ú¬ÛÃö®É¶¡»P¤é´Áªº¤èªk¡A·í§Ú­Ì¨Ï¥Î³o¨Ç¤èªk®É¡A¥¦­Ì©Ò¦^À³ªº¬O¤@­Ó¼Æ¦r¡A²{¦b´N½Ð§A§Q¥Îif§PÂ_±Ô­z±NgetDay()¤èªk©Ò¦^À³ªº¼Æ¦rÂà´«¬°¥¿½Tªº¬P´Á¦WºÙ¡G
  1. <BODY>
  2. ¤µ¤Ñ¬O¡G
  3. <Script LANGUAGE="JavaScript">
  4. now = new Date()
  5. weekday=now.getDay()

  6. if  (weekday == 0)
  7. {document.write("¬P´Á¤Ñ")}
  8. if  (weekday == 1)
  9. {document.write("¬P´Á¤@")}
  10. if  (weekday == 2)
  11. {document.write("¬P´Á¤G")}
  12. if  (weekday == 3)
  13. {document.write("¬P´Á¤T")}
  14. if  (weekday == 4)
  15. {document.write("¬P´Á¥|")}
  16. if  (weekday == 5)
  17. {document.write("¬P´Á¤­")}
  18. if  (weekday == 6)
  19. {document.write("¬P´Á¤»")}

  20. </Script>
  21. </BODY>
½Æ»s¥N½X
if- else±ø¥ó§PÂ_±Ô­z
if- else±Ô­zªº·N«ä¬O»¡¡G¡u¦pªG¡K´N°µ¡K§_«h´N¡K.¡C¡v¡A¤]´N¬O·í¤ñ¸û¦¡¦¨¥ß®É°µ¬Y¨Æ¡A¤ñ¸û¦¡¤£¦¨¥ß®É´N°µ¥t¥~¤@¥ó¨Æ¡C
¦b§Ú­Ì¤W¤@¹ê§@¾Ç²ß¸Ì¡G­YÂsÄý®É¶¡¤¶©ó¦­¤W¢¸ÂI¦Ü¤U¤È¢´ÂI®É¡A«h¦bºô­¶¤¤Åã¥Ü¡¨²{¦b¬O¤W¯Z®É¶¡¡¨¡F­YÂsÄýªÌ¨Ã¤£¬O¦b¦­¤W¢¸ÂI¦Ü¤U¤È¢´ÂI®É³o¬q®É¶¡ÂsÄýºô­¶¡A¨º´N¤£·|¦bºô­¶¤¤Åã¥Ü¡¨²{¦b¬O¤W¯Z®É¶¡¡¨¡F ­Y§Ú­Ì§Æ±æ¤£¬O¦b¦­¤W¢¸ÂI¦Ü¤U¤È¢´ÂI³o®É¬qÂsÄý®É·|Åã¥Ü¡¨²{¦b¬O§Ö¼Ö®É¥ú¡¨¡A¨º§Ú­Ì¸Ó¦p¦ó°µ©O¡H©Î³\§A·|»¡¡G´N¦A¥[¤@­Óif±Ô­z¨Ó§PÂ_´N¦æ¤F¡I ¤£¥Î³o»ò³Â·Ð°Õ¡I¨Ï¥Îif-else±ø¥ó§PÂ_±Ô­z´N¦æ¤F°Õ¡I
  1. If  (±ø¥ó¦¡)
  2. {   ±ø¥ó¦¡¦¨¥ßªºµ{¦¡±Ô­z}
  3. else
  4. { ±ø¥ó¦¡¤£¦¨¥ßªºµ{¦¡±Ô­z}
½Æ»s¥N½X
¹ê°µ¾Ç²ß
³]­p¤@JavaScriptµ{¦¡¡A±NÂsÄýªÌ¶}©lÂsÄýºô­¶ªº®É¶¡Åã¥Ü¦bºô­¶¤¤¡A­YÂsÄý®É¶¡¤¶©ó¦­¤W¢¸ÂI¦Ü¤U¤È¢´ÂI®É¡A«h¦P®É¦bºô­¶¤¤Åã¥Ü¡¨²{¦b¬O¤W¯Z®É¶¡¡¨¡F­Y«DÂsÄý®É¶¡¦b¦­¤W¢¸ÂI¦Ü¤U¤È¢´ÂI®É¡A«h¦bºô­¶¤¤Åã¥Ü¡¨ ²{¦b¬O§Ö¼Ö®É¥ú¡¨¡G
  1. <BODY>
  2. ²{¦b®É¶¡¬O¡G
  3. <Script LANGUAGE="JavaScript">
  4. begintime = new Date();
  5. beginhours=begintime.getHours();
  6. beginminutes=begintime.getMinutes();
  7. beginseconds=begintime.getSeconds();
  8. document.write(beginhours+"®É"+beginminutes+"¤À"+beginseconds+"¬í<br>");
  9. if  (beginhours>=9  && beginhours<=17)
  10. {
  11. document.write("²{¦b¬O¤W¯Z®É¶¡");
  12. }
  13. else
  14. {
  15. document.write("²{¦b¬O§Ö¼Ö®É¥ú");
  16. }
  17. </Script>
  18. </BODY>
½Æ»s¥N½X
  ? - :
if-else§PÂ_±Ô­z¨ä¹êÁÙ¦³¤À¨­³á¡I¦pªG§Aı±oif-else§PÂ_±Ô­z¤£º¡·N§Aı±o¤Ó³Â·Ð¡A¨º§Ú­Ì¥i¥H§ï¥Î¤U¦C®æ¦¡ªº¼gªk¡G
  1. (±ø¥ó¦¡) ? ±ø¥ó¦¡¦¨¥ßªº±Ô­z : ±ø¥ó¦¡¤£¦¨¥ßªº±Ô­z
½Æ»s¥N½X
¨Ò¦p¡G
  1. Now = (x>12) ¡H ¡§²{¦b¬O¤U¤È¡¨ ¡G ¡§²{¦b¬O¤W¤È¡¨
½Æ»s¥N½X
¤W¨Ò¡GnowÅܼƪº¤º®e·íx¤j©ó12®É«h¬°¡¨²{¦b¬O¤U¤È¡¨¡A­Yx¤p©ó©ó12®É«h¬°¡¨²{¦b¬O¤W¤È¡¨

¹ê°µ¾Ç²ß
  1. <BODY>
  2. ²{¦b®É¶¡¬O¡G
  3. <Script LANGUAGE="JavaScript">
  4. begintime = new Date();
  5. beginhours=begintime.getHours();
  6. beginminutes=begintime.getMinutes();
  7. beginseconds=begintime.getSeconds();
  8. document.write(beginhours+"®É"+beginminutes+"¤À"+beginseconds+"¬í<br>");
  9. x=(beginhours>=9 && beginhours<=17) ? "²{¦b¬O¤W¯Z®É¶¡" : "²{¦b¬O§Ö¼Ö®É¥ú";
  10. document.write(x);
  11. </Script>
  12. </BODY>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

        ÀR«ä¦Û¦b : ¤p¨Æ¤£°µ¡B¤j¨ÆÃø¦¨¡C
ªð¦^¦Cªí ¤W¤@¥DÃD