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

[·­Òë]High Performance JavaScript(020)

Yielding with Timers  Óö¨Ê±Æ÷Èóöʱ¼äƬ
    Despite your best efforts, there will be times when a JavaScript task cannot be completed in 100 milliseconds or less because of its complexity. In these cases, it's ideal to yield control of the UI thread so that UI updates may occur. Yielding control means stopping JavaScript execution and giving the UI a chance to update itself before continuing to execute the JavaScript. This is where JavaScript timers come into the picture.
    ¾¡¹ÜÄ㾡ÁË×î´óŬÁ¦£¬»¹ÊÇÓÐһЩJavaScriptÈÎÎñÒòΪ¸´ÔÓÐÔÔ­Òò²»ÄÜÔÚ100ºÁÃë»ò¸üÉÙʱ¼äÄÚÍê³É¡£ÕâÖÖÇé¿öÏ£¬ÀíÏë·½·¨ÊÇÈóö¶ÔUIÏ̵߳ĿØÖÆ£¬Ê¹UI¸üпÉÒÔ½øÐС£Èóö¿ØÖÆÒâζ×ÅÍ£Ö¹JavaScriptÔËÐУ¬¸øUIÏ̻߳ú»á½øÐиüУ¬È»ºóÔÙ¼ÌÐøÔËÐÐJavaScript¡£ÓÚÊÇJavaScript¶¨Ê±Æ÷½øÈëÁËÎÒÃǵÄÊÓÒ°¡£
Timer Basics  ¶¨Ê±Æ÷»ù´¡
    Timers are created in JavaScript using either setTimeout() or setInterval(), and both accept the same arguments: a function to execute and the amount of time to wait (in milliseconds) before executing it. The setTimeout() function creates a timer that executes just once, whereas the setInterval() function creates a timer that repeats periodically.
    ÔÚJavaScriptÖÐʹÓÃsetTimeout()»òsetInterval()´´½¨¶¨Ê±Æ÷£¬Á½¸öº¯Êý¶¼½ÓÊÕÒ»ÑùµÄ²ÎÊý£ºÒ»¸öÒªÖ´Ðеĺ¯Êý£¬ºÍÒ»¸öÔËÐÐËü֮ǰµÄµÈ´ýʱ¼ä£¨µ¥Î»ºÁÃ룩¡£setTimeout()º¯Êý´´½¨Ò»¸ö¶¨Ê±Æ÷Ö»ÔËÐÐÒ»´Î£¬¶øsetInterval()º¯Êý´´½¨Ò»¸öÖÜÆÚÐÔÖظ´ÔËÐеĶ¨Ê±Æ÷¡£
    The way that timers interact with the UI thread is helpful for breaking up long-running scripts into shorter segments. Calling setTimeout() or setInterval() tells the JavaScript engine to wait a certain amount of time and then add a JavaScript task to the UI queue. For example:
    ¶¨Ê±Æ÷ÓëUIÏ߳̽»»¥µÄ·½Ê½ÓÐÖúÓڷֽⳤÔËÐнű¾³ÉΪ½Ï¶ÌµÄƬ¶Ï¡£µ÷ÓÃsetTimeout()»òsetInterval()¸æËßJavaScriptÒýÇæµÈ´ýÒ»¶¨Ê±¼äÈ»ºó½«JavaScriptÈÎÎñÌí¼Óµ½UI¶ÓÁÐÖС£ÀýÈ磺
function greeting(){
  alert("Hello world!");
}
setTimeout(gree


Ïà¹ØÎĵµ£º

javascriptЧÂʾ­Ñé̸(Ò»)

±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔ­À´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾­Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾­¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷Ô­Òò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......

JavaScriptʼþ´óÈ«

JavaScriptʼþ´óÈ«
 
 
click() ¶ÔÏó.click() ʹ¶ÔÏó±»µã»÷¡£
closed ¶ÔÏó.closed ¶ÔÏó´°¿ÚÊÇ·ñÒѹرÕtrue/false
clearTimeout(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetTimeout¶ÔÏó
clearInterval(¶ÔÏó) Çå³ýÒÑÉèÖõÄsetInterval¶ÔÏó
confirm("ÌáʾÐÅÏ¢") µ¯³öÈ·ÈÏ¿ò£¬È·¶¨·µ»ØtrueÈ¡Ïû·µ»Øfalse
cursor:Ñùʽ ¸ü¸ÄÊó±êÑùÊ ......

Javascript±Õ°ü(Closure)

ClosureÖÐÎÄ·­ÒëΪ±Õ°ü.×ÖÃæÉÏÀ´Àí½â¾ÍÊÇ"·â±ÕµÄ°ü".(ÕâÊÇÒ»¾ä·Ï»°)
±Õ°üÊÇʲô?
ÊéÃæ½âÊÍΪ:
Ëùν“±Õ°ü”£¬Ö¸µÄÊÇÒ»¸öÓµÓÐÐí¶à±äÁ¿ºÍ°ó¶¨ÁËÕâЩ±äÁ¿µÄ»·¾³µÄ±í´ïʽ£¨Í¨³£ÊÇÒ»¸öº¯Êý£©£¬Òò¶øÕâЩ±äÁ¿Ò²ÊǸñí´ïʽµÄÒ»²¿·Ö¡£
ÎÒÈÏΪ±Õ°ü¾ÍÊÇÄܹ»¶Á/дº¯ÊýÄÚ²¿µÄijЩ±äÁ¿µÄ×Óº¯Êý,²¢½«ÕâЩ±äÁ¿±£´æ ......

AJAX (Òì²½ JavaScript ºÍ XML)

AJAX (Òì²½ JavaScript ºÍ XML) ÊǸöвúÉúµÄÊõÓï,רΪÃèÊöJavaScriptµÄÁ½ÏîÇ¿´óÐÔÄÜ.ÕâÁ½ÏîÐÔ
ÄÜÔÚ¶àÄêÀ´Ò»Ö±±»ÍøÂ翪·¢ÕßËùºöÂÔ,Ö±µ½×î½üGmail, Google suggestºÍgoogle MapsµÄºá¿Õ³öÊÀ²ÅʹÈË
ÃÇ¿ªÊ¼Òâʶµ½ÆäÖØÒªÐÔ.
ÕâÁ½Ïî±»ºöÊÓµÄÐÔÄÜÊÇ:
* ÎÞÐèÖØÐÂ×°ÔØÕû¸öÒ³Ãæ±ãÄÜÏò·þÎñÆ÷·¢ËÍÇëÇó.
* ¶ÔXMLÎĵµµÄ½âÎöºÍ´¦Àí£® ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ