Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

²»ÌÆÍ»µÄJavaScriptµÄÆßÌõ×¼Ôò

 Ó¢ÎÄÔ­ÎÄ£ºThe seven rules of Unobtrusive JavaScript
Ô­ÎÄ×÷ÕߣºChris Heilmann
¾­¹ý¶àÄêµÄ¿ª·¢¡¢½ÌѧºÍ±àд²»ÌÆÍ»µÄJavaScript£¬ ÎÒ·¢ÏÖÁËÏÂÃæµÄһЩ׼Ôò¡£ÎÒÏ£ÍûËüÃÇ¿ÉÒÔ°ïÖúÄã¶Ô“ΪʲôÕâÑùÉè¼ÆºÍÖ´ÐÐJavaScript±È½ÏºÃ”ÓÐÒ»µãÀí½â¡£ÕâЩ¹æÔòÔø¾­°ïÖúÎÒ¸ü¿ìµØ½»¸¶²úÆ·£¬²¢ÇÒ²úÆ·µÄÖÊÁ¿¸ü¸ß£¬Ò²¸üÈÝÒ×ά»¤¡£
1.²»Òª×öÈκμÙÉè
£¨JavaScriptÊÇÒ»¸ö²»¿É¿¿µÄÖúÊÖ£©
¿ÉÄܲ»ÌÆÍ»µÄJavaScript µÄ×îÖØÒªµÄÒ»¸öÌØÐÔ¾ÍÊÇ——ÄãҪֹͣÈκμÙÉ裺
    * ²»Òª¼ÙÉèJavaScriptÊÇ¿ÉÓõģ¬Äã×îºÃÈÏΪËüºÜÓпÉÄÜÊDz»¿ÉÓõģ¬¶ø²»ÊÇÖ±½ÓÒÀÀµÓÚËü¡£
    * ÔÚÄã¾­¹ý²âÊÔÈ·ÈÏһЩ·½·¨ºÍÊôÐÔ¿ÉÒÔʹÓÃ֮ǰ£¬²»Òª¼ÙÉèä¯ÀÀÆ÷Ö§³ÖËüÃÇ¡£
    * ²»Òª¼ÙÉèHTML´úÂëÈçÄãÏëÏóµÄÄÇÑùÕýÈ·£¬Ã¿´Î¶¼Òª½øÐмì²é£¬²¢ÇÒµ±Æä²»¿ÉÓõÄʱºò¾ÍʲôҲ²»Òª×ö¡£
    * ÈÃJavaScriptµÄ¹¦ÄܶÀÁ¢ÓÚÊäÈëÉ豸
    * Òª¼ÇסÆäËûµÄ½Å±¾¿ÉÄÜ»áÓ°ÏìÄãµÄJavaScriptµÄ¹¦ÄÜ£¬ËùÒÔÒª±£Ö¤ÄãµÄ½Å±¾µÄ×÷ÓÃÓò¾¡¿ÉÄܵذ²È«¡£
ÔÚ¿ªÊ¼Éè¼ÆÄãµÄ½Å±¾Ö®Ç°£¬Òª¿¼ÂǵĵÚÒ»¼þÊÂÇé¾ÍÊǼì²éÒ»ÏÂÄãҪΪÆä±àд½Å±¾µÄHTML´úÂ룬¿´¿´ÓÐʲô¶«Î÷¿ÉÒÔ°ïÖúÄã´ïµ½Ä¿µÄ¡£
2.ÕÒ³ö¹³×Ӻͽڵã¹Øϵ
£¨HTMLÊǽű¾µÄ»ùʯ£©
ÔÚ¿ªÊ¼±àд½Å±¾Ö®Ç°£¬ÒªÏÈ¿´Ò»ÏÂÄãҪΪ֮±àдJavaScriptµÄHTML¡£Èç¹ûHTMLÊÇδ¾­×éÖ¯µÄ»òÕßδ֪µÄ£¬ÄÇôÄ㼸ºõ²»¿ÉÄÜÓÐÒ»¸öºÃµÄ
½Å±¾±àд·½°¸——ºÜ¿ÉÄܾͻá³öÏÖÏÂÃæµÄÇé¿ö£ºÒªÃ´ÊÇ»áÓÃJavaScript´´½¨Ì«¶à±ê¼Ç£¬ÒªÃ´¾ÍÊÇÓ¦ÓÃÌ«ÒÀÀµÓÚJavaScript¡£
ÔÚHTMLÖÐÓÐһЩ¶«Î÷ÐèÒª¿¼ÂÇ£¬ÄǾÍÊǹ³×Ӻͽڵã¹Øϵ¡£
<1>.HTML ¹³×Ó
HTML×î³õµÄºÍ×îÖØÒªµÄ¹³×Ó¾ÍÊÇID£¬¶øÇÒID¿ÉÒÔͨ¹ý×î¿ìµÄDOM·½·¨——getElementById
·ÃÎʵ½¡£Èç¹ûÔÚÒ»¸öÓÐЧµÄHTMLÎĵµÖÐËùÓеÄID¶¼ÊǶÀÒ»ÎÞ¶þµÄ»°£¨ÔÚIEÖйØÓÚname ºÍ ID
ÓÐÒ»¸öbug£¬²»¹ýÓÐЩºÃµÄÀà¿â½â¾öÁËÕâ¸öÎÊÌ⣩£¬Ê¹ÓÃID¾ÍÊÇ°²È«¿É¿¿µÄ£¬²¢ÇÒÒ×ÓÚ²âÊÔ¡£
ÆäËûһЩ¹³×Ó¾ÍÊÇÊÇHTMLÔªËغÍCSSÀ࣬HTMLÔªËØ¿ÉÒÔͨ¹ýgetElementsByTagName·½·¨·ÃÎÊ£¬¶øÔÚ¶àÊýä¯ÀÀÆ÷Öж¼»¹²»ÄÜ
ͨ¹ýÔ­ÉúµÄDOM·½·¨À´·ÃÎÊCSSÀà¡£²»¹ý£¬ÓкܶàÍⲿÀà¿âÌṩÁË¿ÉÒÔ·ÃÎÊCSSÀàÃû£¨ÀàËÆÓÚ getElementsByClassName£©
µÄ·½·¨¡£
<2>.HTML ½Úµã¹Øϵ
¹ØÓÚHTMLµÄÁíÍâ±È½ÏÓÐÒâ˼µÄÒ»µã¾ÍÊDZê¼ÇÖ®¼äµÄ¹Øϵ£¬Ë¼¿¼ÏÂÃæµÄÎÊÌ⣺
    * ÒªÔõÑù²Å¿ÉÒÔ×îÈÝÒ×µØ


Ïà¹ØÎĵµ£º

JavaScriptÃæÏò¶ÔÏó³ÌÐòÉè¼Æ(7): ±Õ°ü

 ±¾²©¿ÍתÔØÓÚ£ºhttp://devbean.javaeye.com/blog/409566
±Õ°üÕâ¸ö¸ÅÄî¿´ÉÏÈ¥ºÜÉî°Â£¬Õâ¸ö´ÊÔÚÀëÉ¢ÊýѧÀïÃæµÄÒâ˼ȷʵ±È½ÏÄÑÓÚÀí½â¡£ÔÚÕâÀÎÒÃÇÏÈ¿ÉÒ԰ѱհüÀí½â³ÉÊÇÒ»ÖÖÄäÃûº¯Êý»òÕßÄäÃûÀà¡£
1. ʲôÊDZհü£¿
ʲôÊDZհü£¿Ò»ÖÖÕýʽµÄ½âÊÍÊÇ£ºËùν±Õ°ü£¬Ö¸µÄÊÇÒ»ÖÖÓµÓкܶà±äÁ¿²¢ÇÒ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïÊ ......

JavaScript Date ¶ÔÏóÓ뺯Êý

JavaScript Date ¶ÔÏóÓ뺯Êý
Ŀ¼
JavaScript_Date¶ÔÏó˵Ã÷
Date¶ÔÏó¹¹Ô캯Êý
Dateº¯ÊýʹÓÃÓï·¨
JavaScript_Dateº¯Êý°´¹¦ÄÜ·ÖÀà
ÈÕÆÚ»ñÈ¡ÀຯÊý
ÈÕÆÚÉèÖÃÀຯÊý
ÈÕÆÚ´òÓ¡ÀຯÊý
ÈÕÆÚ½âÎöÀຯÊý
JavaScript_Dateº¯Êý°´ÕÕ×Öĸ·ÖÀà
JavaScript_Date¶ÔÏó˵Ã÷
DateÖÐÎÄΪ"ÈÕÆÚ"µÄÒâ˼£¬Date¼Ì³Ð×ÔObject¶ÔÏó£¬ ......

ÈçºÎͨ¹ýJavaScriptº¯Êý»ñÈ¡Web±¨±íµ¥Ôª¸ñµÄÖµ

±¨±íÕ¹ÏÖÔÚwebÒ³ÃæÒÔºó£¬ÓÐʱÐèÒª»ñȡijµ¥Ôª¸ñµÄÖµ¡£ÈóǬ±¨±íÖпÉÒÔͨ¹ýÔÚjspÒ³ÃæÖÐÉ趨JavaScriptº¯ÊýÀ´ÊµÏÖÕâ¸ö¹¦ÄÜ¡£ÏÂÃæ¾Íͨ¹ýÒ»¸öÏÂÀý×Ó¼òµ¥½éÉÜÒ»ÏÂÈçºÎͨ¹ýJavaScriptº¯Êý»ñÈ¡Web±¨±íµ¥Ôª¸ñµÄÖµ¡£
Ê×ÏÈ£¬½«·¢²¼±¨±íµÄjspÒ³ÃæÖеı¨±í±êÇ©<report:html>·ÅÔÚÒ»¸ö<table>±êÇ©ÖУ¬ÈçÏÂͼ
ÆäÖÐ<report:h ......

Google¿ªÔ´JavaScript¹¤¾ß Closure

Google¿ªÔ´ÁËÆäÄÚ²¿Ê¹ÓõÄJavaScript¿ª·¢¹¤¾ßClosure£¬Ï£Íû°ïÖúÍⲿ³ÌÐòÔ±¿ª·¢³öËٶȸü¿ìµÄWebÓ¦ÓóÌÐò¡£GoogleÈÏΪͨ¹ýÔÊÐí¿ª·¢ÕßʹÓÃGoogle×Ô¼ºËùÓõŤ¾ß£¬ËûÃDz»½ö¿ÉÒÔ´´Ôì³ö¸ü¿ìµÄ¸»WebÓ¦ÓóÌÐò£¬¶øÇÒÄÜÕæÕýÈÃWeb²åÉϳá°ò¡£Closure JavaScript±àÒëÆ÷ºÍ¿âÔø±»GoogleÓÃÓÚ¿ª·¢Gmail¡¢Google Docs¡¢Google MapsÒÔ¼°ÆäËüÓ¦Ó ......

JavaScriptµÄeval(¡°{JSON object string}¡±)ÎÊÌâ

ÔÚ×öAJAXÓ¦Óÿª·¢µÄʱºò£¬ÎÒÃÇͨ³£Ï²»¶°Ñ·þÎñÆ÷¶Ë·µ»ØµÄJSON¸ñʽ×Ö·û´®ÔÚ¿Í»§¶ËµÄ»Øµ÷º¯ÊýÖаÑËü×÷ΪJavaScript´úÂëÖ´Ðв¢ÓÃÒ»¸ö±äÁ¿±£´æÆðÀ´£¬ÒÔ·½±ãʹÓ÷µ»ØµÄÊý¾Ý¡£Í¨³£µÄ×ö·¨¾ÍÊÇvar jsonData = eval(xmlHttp.responseText)¡£Õâ¿´ÆðÀ´ËƺõÒ»Çж¼ÊÇÕýÈ·µÄ£¬µ«µ±ÄãÔËÐдúÂëµÄʱºò£¬Äã»á·¢ÏÖ±¨“invalid labe”´ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ