如题所述
ä¸ã 让代ç ç®æ´ï¼ä¸äºç®ç¥ç表达æ¹å¼ä¹ä¼äº§çå¾å¥½çä¼å
egï¼x=x+1;å¨ä¸å½±ååè½çæ åµä¸å¯ä»¥ç®å为x++;
äºã åéåæ¹æ³åå°½éå¨ä¸å½±åè¯æçæ åµä¸ç®åãï¼å¯ä»¥éæ©é¦åæ¯å½åï¼
egï¼å®ä¹æ°ç»çé¿åº¦å¯ä»¥åå为ï¼ArrLenèä¸éè¦å为ArrayLengthã
ä¸ã å ³äºJSç循ç¯ï¼å¾ªç¯æ¯ä¸ç§å¸¸ç¨çæµç¨æ§å¶ã
JSæä¾äºä¸ç§å¾ªç¯ï¼for(;;)ãwhile()ãfor(in)ãå¨è¿ä¸ç§å¾ªç¯ä¸for(in)çæçæå·®ï¼å 为å®éè¦æ¥è¯¢Hashé®ï¼å æ¤åºå°½éå°ç¨for(in)循ç¯ï¼for(;;)ãwhile()循ç¯çæ§è½åºæ¬æå¹³ãå½ç¶ï¼æ¨è使ç¨for循ç¯ï¼å¦æ循ç¯åééå¢æéåï¼ä¸è¦åç¬å¯¹å¾ªç¯åéèµå¼ï¼èåºè¯¥ä½¿ç¨åµå¥ç++æâè¿ç®ç¬¦ã
åã å¦æéè¦éåæ°ç»ï¼åºè¯¥å ç¼åæ°ç»é¿åº¦ï¼å°æ°ç»é¿åº¦æ¾å ¥å±é¨åéä¸ï¼é¿å å¤æ¬¡æ¥è¯¢æ°ç»é¿åº¦ã
å 为æ们常常è¦æ ¹æ®å符串ãæ°ç»çé¿åº¦è¿è¡å¾ªç¯ï¼èé常è¿ä¸ªé¿åº¦æ¯ä¸åçï¼æ¯å¦æ¯æ¬¡æ¥è¯¢a.lengthï¼å°±è¦é¢å¤è¿è¡ä¸ä¸ªæä½ï¼èé¢å ævar len=a.lengthï¼åå°±å°äºä¸æ¬¡æ¥è¯¢ã
äºã å°½ééç¨å±é¨åéèä¸æ¯å ¨å±åéã
å±é¨åéç访é®é度è¦æ¯å ¨å±åéç访é®é度æ´å¿«ï¼å ä¸ºå ¨å±åéå ¶å®æ¯window对象çæåï¼èå±é¨åéæ¯æ¾å¨å½æ°çæ éçã
å ã å°½éå°ä½¿ç¨evalã
æ¯æ¬¡ä½¿ç¨evaléè¦æ¶è大éæ¶é´ï¼è¿æ¶å使ç¨JSææ¯æçéå å¯ä»¥å®ç°å½æ°æ¨¡æ¿ã
ä¸ã åå°å¯¹è±¡æ¥æ¾
å 为JavaScriptç解éæ§ï¼æ以a.b.c.d.eï¼éè¦è¿è¡è³å°4次æ¥è¯¢æä½ï¼å æ£æ¥aåæ£æ¥aä¸çbï¼åæ£æ¥bä¸çcï¼å¦æ¤å¾ä¸ãæ以å¦æè¿æ ·ç表达å¼éå¤åºç°ï¼åªè¦å¯è½ï¼åºè¯¥å°½éå°åºç°è¿æ ·ç表达å¼ï¼å¯ä»¥å©ç¨å±é¨åéï¼æå®æ¾å ¥ä¸ä¸ªä¸´æ¶çå°æ¹è¿è¡æ¥è¯¢ã
å «ã å符串è¿æ¥ã
å¦ææ¯è¿½å å符串ï¼æ好使ç¨s+=anotherStræä½ï¼èä¸æ¯è¦ä½¿ç¨s=s+anotherStrã
å¦æè¦è¿æ¥å¤ä¸ªå符串ï¼åºè¯¥å°ä½¿ç¨+=ï¼å¦s+=a;s+=b;s+=c;åºè¯¥åæs+=a + b + cï¼
èå¦ææ¯æ¶éå符串ï¼æ¯å¦å¤æ¬¡å¯¹åä¸ä¸ªå符串è¿è¡+=æä½çè¯ï¼æ好使ç¨ä¸ä¸ªç¼åãæä¹ç¨å¢ï¼ä½¿ç¨JavaScriptæ°ç»æ¥æ¶éï¼æå使ç¨joinæ¹æ³è¿æ¥èµ·æ¥ï¼å¦ä¸
var buf = new Array();for(var i = 0; i < 100; i++){ buf.push(i.toString());}var all = buf.join("");
ä¹ã ç±»å转æ¢
1. ææ°å转æ¢æå符串ï¼åºç¨"" + 1ï¼è½ç¶çèµ·æ¥æ¯è¾ä¸ä¸ç¹ï¼ä½äºå®ä¸è¿ä¸ªæçæ¯æé«çï¼æ§è½ä¸æ¥è¯´ï¼("" +) > String() > .toString() > new String()
å°½é使ç¨ç¼è¯æ¶å°±è½ä½¿ç¨çå é¨æä½è¦æ¯è¿è¡æ¶ä½¿ç¨çç¨æ·æä½è¦å¿«ã
String()å±äºå é¨å½æ°ï¼æ以é度å¾å¿«ï¼è.toString()è¦æ¥è¯¢ååä¸çå½æ°ï¼æ以é度éè²ä¸äºï¼new String()ç¨äºè¿åä¸ä¸ªç²¾ç¡®çå¯æ¬ã
2. æµ®ç¹æ°è½¬æ¢ææ´åï¼è¿ä¸ªæ´å®¹æåºéï¼å¾å¤äººå欢使ç¨parseInt()ï¼å ¶å®parseInt()æ¯ç¨äºå°å符串转æ¢ææ°åï¼èä¸æ¯æµ®ç¹æ°åæ´åä¹é´ç转æ¢ï¼æ们åºè¯¥ä½¿ç¨Math.floor()æè Math.round()ãMathæ¯å é¨å¯¹è±¡ï¼æ以Math.floor()å ¶å®å¹¶æ²¡æå¤å°æ¥è¯¢æ¹æ³åè°ç¨çæ¶é´ï¼é度æ¯æå¿«çã
3. 对äºèªå®ä¹ç对象ï¼å¦æå®ä¹äºtoString()æ¹æ³æ¥è¿è¡ç±»å转æ¢çè¯ï¼æ¨èæ¾å¼è°ç¨toString()ï¼å 为å é¨çæä½å¨å°è¯ææå¯è½æ§ä¹åï¼ä¼å°è¯å¯¹è±¡çtoString()æ¹æ³å°è¯è½å¦è½¬å为Stringï¼æ以ç´æ¥è°ç¨è¿ä¸ªæ¹æ³æçä¼æ´é«
åã å°½éä½ç¨JSONæ ¼å¼æ¥å建对象ï¼èä¸æ¯var obj=new Object()æ¹æ³ã
å 为åè æ¯ç´æ¥å¤å¶ï¼èåè éè¦è°ç¨æé å¨ï¼å èåè çæ§è½æ´å¥½ã
åä¸ã å½éè¦ä½¿ç¨æ°ç»æ¶ï¼ä¹å°½é使ç¨JSONæ ¼å¼çè¯æ³ï¼
使ç¨JSONæ ¼å¼çè¯æ³å³ç´æ¥ä½¿ç¨å¦ä¸è¯æ³å®ä¹æ°ç»ï¼[parrm,param,param...],èä¸æ¯éç¨new Array(parrm,param,param...)è¿ç§è¯æ³ãå 为使ç¨JSONæ ¼å¼çè¯æ³æ¯å¼æç´æ¥è§£éçãèåè åéè¦è°ç¨Arrayçæé å¨ã
åäºã 对å符串è¿è¡å¾ªç¯æä½ï¼ä¾å¦æ¿æ¢ãæ¥æ¾ï¼å°±ä½¿ç¨æ£å表达å¼ã
å 为JSç循ç¯é度æ¯è¾æ ¢ï¼èæ£å表达å¼çæä½æ¯ç¨CåæçAPIï¼æ§è½æ¯è¾å¥½ã
åä¸ã æå ¥HTML
å¾å¤äººå欢å¨JavaScriptä¸ä½¿ç¨document.writeæ¥ç»é¡µé¢çæå 容ãäºå®ä¸è¿æ ·çæçè¾ä½ï¼å¦æéè¦ç´æ¥æå ¥HTMLï¼å¯ä»¥æ¾ä¸ä¸ªå®¹å¨å ç´ ï¼æ¯å¦æå®ä¸ä¸ªdivæè spanï¼å¹¶è®¾ç½®ä»ä»¬çinnerHTMLæ¥å°èªå·±çHTML代ç æå ¥å°é¡µé¢ä¸ã
ååã 对象æ¥è¯¢
使ç¨[ââ]æ¥è¯¢è¦æ¯.items()æ´å¿«
åäºã å®æ¶å¨
å¦æé对çæ¯ä¸æè¿è¡ç代ç ï¼ä¸åºè¯¥ä½¿ç¨setTimeoutï¼èåºè¯¥æ¯ç¨setIntervalãsetTimeoutæ¯æ¬¡è¦éæ°è®¾ç½®ä¸ä¸ªå®æ¶å¨ã
åå ã å°½éåå°DOMè°ç¨
å¨Webå¼åä¸ï¼JavaScriptçä¸ä¸ªå¾éè¦çä½ç¨å°±æ¯å¯¹DOMè¿è¡æä½ãå¯æ¯å¯¹DOMçæä½æ¯é常æè´µçï¼å 为è¿ä¼å¯¼è´æµè§å¨æ§è¡åæµ ï¼reflowï¼æä½ãæ们åºè¯¥å°½å¯è½çåå°DOMæä½ã
egï¼x=x+1;å¨ä¸å½±ååè½çæ åµä¸å¯ä»¥ç®å为x++;
äºã åéåæ¹æ³åå°½éå¨ä¸å½±åè¯æçæ åµä¸ç®åãï¼å¯ä»¥éæ©é¦åæ¯å½åï¼
egï¼å®ä¹æ°ç»çé¿åº¦å¯ä»¥åå为ï¼ArrLenèä¸éè¦å为ArrayLengthã
ä¸ã å ³äºJSç循ç¯ï¼å¾ªç¯æ¯ä¸ç§å¸¸ç¨çæµç¨æ§å¶ã
JSæä¾äºä¸ç§å¾ªç¯ï¼for(;;)ãwhile()ãfor(in)ãå¨è¿ä¸ç§å¾ªç¯ä¸for(in)çæçæå·®ï¼å 为å®éè¦æ¥è¯¢Hashé®ï¼å æ¤åºå°½éå°ç¨for(in)循ç¯ï¼for(;;)ãwhile()循ç¯çæ§è½åºæ¬æå¹³ãå½ç¶ï¼æ¨è使ç¨for循ç¯ï¼å¦æ循ç¯åééå¢æéåï¼ä¸è¦åç¬å¯¹å¾ªç¯åéèµå¼ï¼èåºè¯¥ä½¿ç¨åµå¥ç++æâè¿ç®ç¬¦ã
åã å¦æéè¦éåæ°ç»ï¼åºè¯¥å ç¼åæ°ç»é¿åº¦ï¼å°æ°ç»é¿åº¦æ¾å ¥å±é¨åéä¸ï¼é¿å å¤æ¬¡æ¥è¯¢æ°ç»é¿åº¦ã
å 为æ们常常è¦æ ¹æ®å符串ãæ°ç»çé¿åº¦è¿è¡å¾ªç¯ï¼èé常è¿ä¸ªé¿åº¦æ¯ä¸åçï¼æ¯å¦æ¯æ¬¡æ¥è¯¢a.lengthï¼å°±è¦é¢å¤è¿è¡ä¸ä¸ªæä½ï¼èé¢å ævar len=a.lengthï¼åå°±å°äºä¸æ¬¡æ¥è¯¢ã
äºã å°½ééç¨å±é¨åéèä¸æ¯å ¨å±åéã
å±é¨åéç访é®é度è¦æ¯å ¨å±åéç访é®é度æ´å¿«ï¼å ä¸ºå ¨å±åéå ¶å®æ¯window对象çæåï¼èå±é¨åéæ¯æ¾å¨å½æ°çæ éçã
å ã å°½éå°ä½¿ç¨evalã
æ¯æ¬¡ä½¿ç¨evaléè¦æ¶è大éæ¶é´ï¼è¿æ¶å使ç¨JSææ¯æçéå å¯ä»¥å®ç°å½æ°æ¨¡æ¿ã
ä¸ã åå°å¯¹è±¡æ¥æ¾
å 为JavaScriptç解éæ§ï¼æ以a.b.c.d.eï¼éè¦è¿è¡è³å°4次æ¥è¯¢æä½ï¼å æ£æ¥aåæ£æ¥aä¸çbï¼åæ£æ¥bä¸çcï¼å¦æ¤å¾ä¸ãæ以å¦æè¿æ ·ç表达å¼éå¤åºç°ï¼åªè¦å¯è½ï¼åºè¯¥å°½éå°åºç°è¿æ ·ç表达å¼ï¼å¯ä»¥å©ç¨å±é¨åéï¼æå®æ¾å ¥ä¸ä¸ªä¸´æ¶çå°æ¹è¿è¡æ¥è¯¢ã
å «ã å符串è¿æ¥ã
å¦ææ¯è¿½å å符串ï¼æ好使ç¨s+=anotherStræä½ï¼èä¸æ¯è¦ä½¿ç¨s=s+anotherStrã
å¦æè¦è¿æ¥å¤ä¸ªå符串ï¼åºè¯¥å°ä½¿ç¨+=ï¼å¦s+=a;s+=b;s+=c;åºè¯¥åæs+=a + b + cï¼
èå¦ææ¯æ¶éå符串ï¼æ¯å¦å¤æ¬¡å¯¹åä¸ä¸ªå符串è¿è¡+=æä½çè¯ï¼æ好使ç¨ä¸ä¸ªç¼åãæä¹ç¨å¢ï¼ä½¿ç¨JavaScriptæ°ç»æ¥æ¶éï¼æå使ç¨joinæ¹æ³è¿æ¥èµ·æ¥ï¼å¦ä¸
var buf = new Array();for(var i = 0; i < 100; i++){ buf.push(i.toString());}var all = buf.join("");
ä¹ã ç±»å转æ¢
1. ææ°å转æ¢æå符串ï¼åºç¨"" + 1ï¼è½ç¶çèµ·æ¥æ¯è¾ä¸ä¸ç¹ï¼ä½äºå®ä¸è¿ä¸ªæçæ¯æé«çï¼æ§è½ä¸æ¥è¯´ï¼("" +) > String() > .toString() > new String()
å°½é使ç¨ç¼è¯æ¶å°±è½ä½¿ç¨çå é¨æä½è¦æ¯è¿è¡æ¶ä½¿ç¨çç¨æ·æä½è¦å¿«ã
String()å±äºå é¨å½æ°ï¼æ以é度å¾å¿«ï¼è.toString()è¦æ¥è¯¢ååä¸çå½æ°ï¼æ以é度éè²ä¸äºï¼new String()ç¨äºè¿åä¸ä¸ªç²¾ç¡®çå¯æ¬ã
2. æµ®ç¹æ°è½¬æ¢ææ´åï¼è¿ä¸ªæ´å®¹æåºéï¼å¾å¤äººå欢使ç¨parseInt()ï¼å ¶å®parseInt()æ¯ç¨äºå°å符串转æ¢ææ°åï¼èä¸æ¯æµ®ç¹æ°åæ´åä¹é´ç转æ¢ï¼æ们åºè¯¥ä½¿ç¨Math.floor()æè Math.round()ãMathæ¯å é¨å¯¹è±¡ï¼æ以Math.floor()å ¶å®å¹¶æ²¡æå¤å°æ¥è¯¢æ¹æ³åè°ç¨çæ¶é´ï¼é度æ¯æå¿«çã
3. 对äºèªå®ä¹ç对象ï¼å¦æå®ä¹äºtoString()æ¹æ³æ¥è¿è¡ç±»å转æ¢çè¯ï¼æ¨èæ¾å¼è°ç¨toString()ï¼å 为å é¨çæä½å¨å°è¯ææå¯è½æ§ä¹åï¼ä¼å°è¯å¯¹è±¡çtoString()æ¹æ³å°è¯è½å¦è½¬å为Stringï¼æ以ç´æ¥è°ç¨è¿ä¸ªæ¹æ³æçä¼æ´é«
åã å°½éä½ç¨JSONæ ¼å¼æ¥å建对象ï¼èä¸æ¯var obj=new Object()æ¹æ³ã
å 为åè æ¯ç´æ¥å¤å¶ï¼èåè éè¦è°ç¨æé å¨ï¼å èåè çæ§è½æ´å¥½ã
åä¸ã å½éè¦ä½¿ç¨æ°ç»æ¶ï¼ä¹å°½é使ç¨JSONæ ¼å¼çè¯æ³ï¼
使ç¨JSONæ ¼å¼çè¯æ³å³ç´æ¥ä½¿ç¨å¦ä¸è¯æ³å®ä¹æ°ç»ï¼[parrm,param,param...],èä¸æ¯éç¨new Array(parrm,param,param...)è¿ç§è¯æ³ãå 为使ç¨JSONæ ¼å¼çè¯æ³æ¯å¼æç´æ¥è§£éçãèåè åéè¦è°ç¨Arrayçæé å¨ã
åäºã 对å符串è¿è¡å¾ªç¯æä½ï¼ä¾å¦æ¿æ¢ãæ¥æ¾ï¼å°±ä½¿ç¨æ£å表达å¼ã
å 为JSç循ç¯é度æ¯è¾æ ¢ï¼èæ£å表达å¼çæä½æ¯ç¨CåæçAPIï¼æ§è½æ¯è¾å¥½ã
åä¸ã æå ¥HTML
å¾å¤äººå欢å¨JavaScriptä¸ä½¿ç¨document.writeæ¥ç»é¡µé¢çæå 容ãäºå®ä¸è¿æ ·çæçè¾ä½ï¼å¦æéè¦ç´æ¥æå ¥HTMLï¼å¯ä»¥æ¾ä¸ä¸ªå®¹å¨å ç´ ï¼æ¯å¦æå®ä¸ä¸ªdivæè spanï¼å¹¶è®¾ç½®ä»ä»¬çinnerHTMLæ¥å°èªå·±çHTML代ç æå ¥å°é¡µé¢ä¸ã
ååã 对象æ¥è¯¢
使ç¨[ââ]æ¥è¯¢è¦æ¯.items()æ´å¿«
åäºã å®æ¶å¨
å¦æé对çæ¯ä¸æè¿è¡ç代ç ï¼ä¸åºè¯¥ä½¿ç¨setTimeoutï¼èåºè¯¥æ¯ç¨setIntervalãsetTimeoutæ¯æ¬¡è¦éæ°è®¾ç½®ä¸ä¸ªå®æ¶å¨ã
åå ã å°½éåå°DOMè°ç¨
å¨Webå¼åä¸ï¼JavaScriptçä¸ä¸ªå¾éè¦çä½ç¨å°±æ¯å¯¹DOMè¿è¡æä½ãå¯æ¯å¯¹DOMçæä½æ¯é常æè´µçï¼å 为è¿ä¼å¯¼è´æµè§å¨æ§è¡åæµ ï¼reflowï¼æä½ãæ们åºè¯¥å°½å¯è½çåå°DOMæä½ã
温馨提示:答案为网友推荐,仅供参考