1 ´´½¨½Å±¾¿é
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 Òþ²Ø½Å±¾´úÂë
1: <script language=”JavaScript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </script>
ÔÚ²»Ö§³ÖJavaScriptµÄä¯ÀÀÆ÷Öн«²»Ö´ÐÐÏà¹Ø´úÂë
3 ä¯ÀÀÆ÷²»Ö§³ÖµÄʱºòÏÔʾ
1: <noscript>
2: Hello to the non-JavaScript browser.
3: </noscript>
4 Á´½ÓÍⲿ½Å±¾Îļþ
1: <script language=”JavaScript” src="/”filename.js"”></script>
5 ×¢Êͽű¾
1: // This is a comment
2: document.write(“Hello”); // This is a comment
3: /*
4: All of this
5: is a comment
6: */
6 Êä³ ......
1.Date
ÊôÐÔ(1):
constructor Ëù½¨Á¢¶ÔÏóµÄº¯Êý²Î¿¼
prototype Äܹ»Îª¶ÔÏó¼ÓÈëµÄÊôÐԺͷ½·¨
·½·¨(43):
getDay() ·µ»ØÒ»ÖÜÖеĵڼ¸Ìì(0-6)
getYear() ·µ»ØÄê·Ý.2000ÄêÒÔǰΪ2λ,2000(°üº¬)ÒÔºóΪ4λ
getFullYear() ·µ»ØÍêÕûµÄ4λÄê·ÝÊý
getMonth() ·µ»ØÔ·ÝÊý(0-11)
getDate() ·µ»ØÈÕ(1-31)
getHours() ·µ»ØСʱÊý(0-23)
getMinutes() ·µ»Ø·ÖÖÓ(0-59)
getSeconds() ·µ»ØÃëÊý(0-59)
getMilliseconds() ·µ»ØºÁÃë(0-999)
getUTCDay() ÒÀ¾Ý¹ú¼Êʱ¼äÀ´µÃµ½ÏÖÔÚÊÇÐÇÆÚ¼¸(0-6)
getUTCFullYear() ÒÀ¾Ý¹ú¼Êʱ¼äÀ´µÃµ½ÍêÕûµÄÄê·Ý
getUTCMonth() ÒÀ¾Ý¹ú¼Êʱ¼äÀ´µÃµ½Ô·Ý(0-11)
getUTCDate() ÒÀ¾Ý¹ú¼Êʱ¼äÀ´µÃµ½ÈÕ(1-31)
getUTCHours() ÒÀ¾Ý¹ú¼Êʱ¼ ......
1.document.formName.item("itemName") ÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓÃdocument.formName.item("itemName")»òdocument.formName.elements["elementName"];FirefoxÏÂ,Ö»ÄÜʹÓÃdocument.formName.elements["elementName"].
½â¾ö·½·¨:ͳһʹÓÃdocument.formName.elements["elementName"].
2.¼¯ºÏÀà¶ÔÏóÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓÃ()»ò[]»ñÈ¡¼¯ºÏÀà¶ÔÏó;FirefoxÏÂ,Ö»ÄÜʹÓÃ[]»ñÈ¡¼¯ºÏÀà¶ÔÏó.
½â¾ö·½·¨:ͳһʹÓÃ[]»ñÈ¡¼¯ºÏÀà¶ÔÏó.
3.×Ô¶¨ÒåÊôÐÔÎÊÌâ
˵Ã÷:IEÏÂ,¿ÉÒÔʹÓûñÈ¡³£¹æÊôÐԵķ½·¨À´»ñÈ¡×Ô¶¨ÒåÊôÐÔ,Ò²¿ÉÒÔʹÓÃgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ;FirefoxÏÂ,Ö»ÄÜʹÓÃgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ.
½â¾ö·½·¨:ͳһͨ¹ýgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ.
4.eval("idName")ÎÊÌâ
˵Ã÷:IEÏÂ,,¿ÉÒÔʹÓÃeval("idName")»ògetElementById("idName")À´È¡µÃidΪidNameµÄHTML¶ÔÏó;FirefoxÏÂÖ»ÄÜʹÓÃgetElementById("idName")À´È¡µÃidΪidNameµÄHTML¶ÔÏó.
½â¾ö·½·¨:ͳһÓÃgetElementById("idName")À´È¡µÃidΪidNameµÄHTML¶ÔÏó.
5.±äÁ¿ÃûÓëijHTML¶ÔÏóIDÏàͬµÄÎÊÌâ
˵Ã÷:IEÏÂ,HTML¶ÔÏóµÄID¿ÉÒÔ×÷ΪdocumentµÄÏÂÊô¶ÔÏó±äÁ¿ÃûÖ±½ÓʹÓÃ;FirefoxÏÂÔò²»ÄÜ.FirefoxÏÂ,¿ÉÒÔʹÓÃÓëHTML¶ÔÏóIDÏàͬµÄ±äÁ¿Ã ......
1ÅжÏselectÑ¡ÏîÖÐ ÊÇ·ñ´æÔÚValue="paraValue"µÄItem
2ÏòselectÑ¡ÏîÖÐ ¼ÓÈëÒ»¸öItem
3´ÓselectÑ¡ÏîÖРɾ³ýÒ»¸öItem
4ɾ³ýselectÖÐÑ¡ÖеÄÏî
5ÐÞ¸ÄselectÑ¡ÏîÖÐ value="paraValue"µÄtextΪ"paraText"
6ÉèÖÃselectÖÐtext="paraText"µÄµÚÒ»¸öItemΪѡÖÐ
7ÉèÖÃselectÖÐvalue="paraValue"µÄItemΪѡÖÐ
8µÃµ½selectµÄµ±Ç°Ñ¡ÖÐÏîµÄvalue
9µÃµ½selectµÄµ±Ç°Ñ¡ÖÐÏîµÄtext
10µÃµ½selectµÄµ±Ç°Ñ¡ÖÐÏîµÄIndex
11Çå¿ÕselectµÄÏî
// 1.ÅжÏselectÑ¡ÏîÖÐ ÊÇ·ñ´æÔÚValue="paraValue"µÄItem
function jsSelectIsExitItem(objSelect, objItemValue) {
var isExit = false;
for (var i = 0; i < objSelect.options.length; i++) {
if (objSelect.options[i].value == objItemValue) {
isExit = true;
break;
}
}
return isExit;
}
// 2.ÏòselectÑ¡ÏîÖÐ ¼ÓÈëÒ» ......
¼Ì³Ð»úÖÆ£¬Ëµµ½¼Ì³Ð£¬¾ÍÒªÏëµ½´Ó»ùÀ࿪ʼ£¬µ«ÊÇJavaScriptÖеÄÀàÓÐÁ½´óÀࣺһ£¬ÄÚǶµÄ£»¶þ£¬Óû§×Ô¶¨Ò壻һ°ãÇ°Õß²»»á±»ÓÃÀ´×ö»ùÀ࣬ÔÒòÊÇΪÁ˱£ÕÏjsµÄ°²È«¡£µ«ÊÇÎÒÃÇ¿ÉÒÔͨ¹ýprototypeÀ´¶Ô»ùÀà½øÐÐÀ©³ä£¬Ôö¼ÓÎÒÃÇÏëÒªµÄÊôÐԺͷ½·¨¡£ÒÔÏÂÊÇ×Ô¼º¶Ô¼Ì³ÐµÄ¼¸ÖÖ·½Ê½µÄÀí½â¡£
1> ¶ÔÏóð³ä£¬ÊÇJavaScript ºÍ ECMAScriptʵÏּ̳еķ½·¨£¬ÔÚѧϰ¶ÔÏóð³äʵÏּ̳ÐÇ°ÎÒÃǵÄÏÈÁ˽â¹Ø¼ü×Ö this µÄʹÓã¬ÀýÈ磺
function classA(color){
this.color = color;
this.show = function(){alert(this.color);}
}
/*
Note:
1> this ´ú±íµÄÊÇclassAº¯ÊýËù¹¹½¨µÄ¶ÔÏ󣬶ø·Çº¯ÊýclassA¶ÔÏó±¾ÉíÕâÑù˵Ö÷ÒªÊÇΪÁ˱ÜÃ⣨function is object£©µÄÓ°Ïì;
2> ÔÚ¹¹½¨classA¶ÔÏóʱ£¬ÊÇͨ¹ýthisÀ´³õʼ»¯µÄÊôÐԺͷ½·¨µÄ£¬Èç¹ûÓÃclassBµÄthisȥð³äclassAµÄthis£¬ÄÇô¾ÍʵÏÖÁ˼òµ¥µÄ¼Ì³ÐÁË
*/
2>¼Ì³Ð»úÖƵÄʵÏÖ·½Ê½£º
NO1£º¶ÔÏóð³ä
¶ÔÏóð³äµÄÔÀí£ºº¯ÊýclassAͨ¹ýthisÀ´³õʼ»¯ÊôÐԺͷ½ ......
keycode 0 =
keycode 1 =
keycode 2 =
keycode 3 =
keycode 4 =
keycode 5 =
keycode 6 =
keycode 7 =
keycode 8 = BackSpace BackSpace
keycode 9 = Tab Tab
keycode 10 =
keycode 11 =
keycode 12 = Clear
keycode 13 = Enter
keycode 14 =
keycode 15 =
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 21 =
keycode 22 =
keycode 23 = ......