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

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

XMLHttpRequest Script Injection  XHR½Å±¾×¢Èë
    Another approach to nonblocking scripts is to retrieve the JavaScript code using an XMLHttpRequest (XHR) object and then inject the script into the page. This technique involves creating an XHR object, downloading the JavaScript file, then injecting the JavaScript code into the page using a dynamic <script> element. Here's a simple example:
    ÁíÒ»¸öÒÔ·Ç×èÈû·½Ê½»ñµÃ½Å±¾µÄ·½·¨ÊÇʹÓÃXMLHttpRequest(XHR)¶ÔÏ󽫽ű¾×¢Èëµ½Ò³ÃæÖС£´Ë¼¼ÊõÊ×ÏÈ´´½¨Ò»¸öXHR¶ÔÏó£¬È»ºóÏÂÔØJavaScriptÎļþ£¬½Ó×ÅÓÃÒ»¸ö¶¯Ì¬<script>ÔªËØ½«JavaScript´úÂë×¢ÈëÒ³Ãæ¡£ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÀý×Ó£º
var xhr = new XMLHttpRequest();
xhr.open("get", "file1.js", true);
xhr.onreadystatechange = function(){
  if (xhr.readyState == 4){
    if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304){
      var script = document.createElement_x("script");
      script.type = "text/javascript";
      script.text = xhr.responseText;
      document.body.appendChild(script);
    }
  }
};
xhr.send(null);
    This code sends a GET request for the file file1.js. The onreadystatechange event handler checks for a readyState of 4 and then verifies that the HTTP status code is valid (anything in the 200 range means a valid response, and 304 means a cached response). If a valid response has been received, then a new <script> element is created and its text property is assigned to the responseText received from the server. Doing so essentially creates a <script> element with inline code. Once the new <script> element is added to the document, the code is executed and is ready to use.
    ´Ë´úÂëÏò·þÎñÆ÷·¢ËÍÒ»¸ö»ñÈ¡file1.jsÎļþµÄGETÇëÇó¡£onreadystatechangeʼþ´¦Àíº¯Êý¼ì²éreadyStateÊDz»ÊÇ4£¬È»ºó¼ì²éHTTP״̬ÂëÊDz»ÊÇÓÐЧ£¨2XX±íʾÓÐ


Ïà¹ØÎĵµ£º

javascriptÖÐevent.keycode

javascriptÖÐevent.keycode
 keycode 8 = BackSpace BackSpace
keycode 9 = Tab Tab
keycode 12 = Clear
keycode 13 = Enter
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 27 = Escape Escape
keycode 32 = space space ......

JavaScript»ù´¡—¶ÔÏó

¡¡´Ó2004ÄêϰëÄ꿪ʼѧϰWeb±à³ÌÖÁ½ñ3ÄêÓÐÓà¡£´ÓHTML£¬asp¿ªÊ¼µ½ÏÖÔÚµÄVS2008һ·ѧ¹ýÀ´£¬ÆäÖÐѧµÄ×î¶àµÄ»¹ÊÇ·þÎñÆ÷¶Ë±à³Ì£¬¶Ô¿Í»§¶Ë±à³ÌµÄѧϰ»¹ÊDz»³Éϵͳ¡£ËäÈ»Ôںܶà¸öϵͳÀïÃæÓ¦Óùý½Å±¾£¬ÓÐЩ»¹Æðµ½Á˱ȽÏÖØÒªµÄ×÷Óᣵ«Ò»Ö±ÊÇÖ»ÖªÆäÈ»²»ÖªÆäËùÒÔÈ»£¬ÓõÄÊÇСÐÄÒíÒí¡£ÏÖÔڽű¾±à³Ì´ÓÒÔǰµÄ"µñ³æÐ¡¼¼"±ä³ÉÁËÒ»¸öWeb¿ª ......

JavaScript ´´½¨Àà/¶ÔÏóµÄ¼¸ÖÖ·½Ê½

ÔÚJSÖУ¬´´½¨¶ÔÏó£¨Create Object£©²¢²»ÍêÈ«ÊÇÎÒÃÇʱ³£ËµµÄ´´½¨Àà¶ÔÏó£¬JSÖеĶÔÏóÇ¿µ÷µÄÊÇÒ»ÖÖ¸´ºÏÀàÐÍ£¬JSÖд´½¨¶ÔÏó¼°¶Ô¶ÔÏóµÄ·ÃÎÊÊǼ«ÆäÁé»îµÄ¡£
JS¶ÔÏóÊÇÒ»ÖÖ¸´ºÏÀàÐÍ£¬ËüÔÊÐíÄãͨ¹ý±äÁ¿Ãû´æ´¢ºÍ·ÃÎÊ£¬»»Ò»ÖÖ˼·£¬¶ÔÏóÊÇÒ»¸öÎÞÐòµÄÊôÐÔ¼¯ºÏ£¬¼¯ºÏÖеÄÿһÏî¶¼ÓÉÃû³ÆºÍÖµ×é³É£¨ÌýÆðÀ´ÊDz»ÊǺÜÏñÎÒÃdz£Ìý˵µÄHASH±í¡¢× ......

Ò»¼ÒÖ®ÑÔ£ºËµËµ JavaScript µÄÀà³ÉÔ±µÄ·ÃÎÊ¿ØÖÆ

¿´ÊéµÄʱºòÓöµ½ÕâÑùÒ»¸öÎÊÌ⣬³ÌÐò´úÂëÈçÏÂ
var ob = function(){
var obj = this;
function fn1(){
alert( obj === window );//false
alert( this === window );//ture
}
this.fn2 = function() {
fn1();
}

µ±Ê±ºÜ²»Ã÷°×fn1ÀïÃæµÚ¶þ¸öalertµÄ½á¹û£¬Îª ......

javascript calendar

<SCRIPT>
//ÅжÏyÄêµÄÅ©ÀúÖÐÄǸöÔÂÊÇÈòÔÂ,²»ÊÇÈòÔ·µ»Ø0
function leapMonth(y){
return(lunarInfo[y-1900]&0xf);
}
var lunarInfo=new Array(
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ