javascriptÓÐÈçÏÂÊý¾ÝÀàÐ͵Äת»»·½·¨£º
Ò»£¬×ª»»³ÉÊý×Ö xxx*1.0
ת»»³É×Ö·û´® xxx+""
¶þ£¬´ÓÒ»¸öÖµÖÐÌáÈ¡ÁíÒ»ÖÖÀàÐ͵ÄÖµ£¬²¢Íê³Éת»»¹¤×÷¡£
1.ÌáÈ¡×Ö·û´®ÖеÄÕûÊý£ºparseInt();
Àý£ºparseInt("123zhang")µÄ½á¹ûΪ123
2.ÌáÈ¡×Ö·û´®Öеĸ¡µãÊý£ºparseFloat();
Àý£ºparseFloat("0.55zhang")µÄ½á¹ûΪ0.55
3.Ö´ÐÐÓÃ×Ö·û´®±íʾµÄÒ»¶Îjavascript´úÂ룺eval();
Àý£ºzhang=eval("1+1")µÄ½á¹ûzhang=2
4. ת»»³É×Ö·û´®£º toString() ;
Àý£ºzhang=eval("1+1")µÄ½á¹ûzhang=2
Èý£¬Êǽ«Õû¸öÖµ´ÓÒ»ÖÖÀàÐÍת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ£¨³Æ×÷»ù±¾Êý¾ÝÀàÐÍת»»£©£¬
»ù±¾Êý¾ÝÀàÐÍת»»µÄÈýÖÖ·½·¨£º
1.ת»»Îª×Ö·ûÐÍ£ºString() ; Àý£ºString(678)µÄ½á¹ûΪ"678"
2.ת»»ÎªÊýÖµÐÍ£ºNumber() ; Àý£ºNumber("678")µÄ½á¹ûΪ678
3.ת»»Îª²¼¶ûÐÍ£ºBoolean() ; Àý£ºBoolean("aaa")µÄ½á¹ûΪtrue
ʹÓÃÕâЩ·½·¨Ê±£¬ÈçÓбØÒª£¬¾¡Á¿¶Ô²ÎÊýºÍ ·½·¨µÄÖ´ÐнøÐÐÅжϺÍÒì³£´¦Àí²Ù×÷¡£
ÓÐÔڲο¼ÎĵµÖп´µ½£¬ÈçϹØÓÚÖ´ÐÐЧÂʵÄ×ܽ᣺
ÔÚIE Ï£¬µÚÒ»ÖÖËÙ¶È×î¿ì£¬µÚ¶þÖÖ´ÎÖ®£¬µÚÈýÖÖ×î²î£¬µ«²î¾à²»¹ý10Íò´Î£¬²î¼¸Ê®°ÙÀ´ºÁÃë¶øÒÑ¡£
ÔÚFFÏ£¬µÚÒ»Öֺ͵ڶþÖÖ»ù±¾ÉÏÏ൱£¬µÚÈýÖÖ×îÂý¡£
ËٶȲî±ð»ù±¾ÉÏ¿ÉÒÔºöÂÔ¡£ÒòΪ²î¾àºÜС¡£
µ«ÊÇ£¬´Ó´úÂëµÄ¼ò½àÐÔ£¬ µÚÒ»ÖÖÃ÷ÏÔд·¨¼ò±ã£¬¶øÇÒÒ²Ò׶Á£¬
¶øÇÒ²»»á³öÏÖµÚ¶þÖÖµÄ ÒòΪ ij¸ö¶ÔÏóûÓÐ toString ·½·¨¶ø±¨´íµÄÎÊÌâ¡£¿öÇÒËûʼÖÕÒ²ÊÇ×î¿ìµÄ¡£
ËùÒÔ£¬¸öÈËÏ°¹ßʹÓõÚÒ»ÖÖ·½Ê½À´Íê³ÉÊý¾ÝÀàÐ͵Äת»»
µ«ÊÇ£¬±ÈÈçÐèÒª¡°123456abcd¡±À´ÌáÈ¡ÆäÖеÄÊý×Ö£¬ÄÇ×ÔÈ»µ±ÓÃparsetInt£¬ºÍparseFloatÖ®ÀàµÄº¯Êý¡£
µ«ÊÇҪעÒ⣬ÓÐʱºò ת»»µÄ½á¹ûÊÇ NaN µÈ£¬ÐèÒªÅжÏһϡ£
ÀýÒì³£´¦ÀíÈç £º
//Ö´ÐÐÎı¾¿òÄÚµÄÓï¾ä£¬ÓÃeval ·µ»ØÓï¾äÖ´ÐкóµÄÖµ function doFunction(str) { var result = str.replace(new RegExp("\"", "gm"), ""); //ÅжÏÓï¾äÊÇ·ñºÏ·¨ var reg = /\s*[A-Za-z]+\s*\('.+'\)\s*$/; if (result.match(reg)){ // »òÕßÓà reg.test(result); ·½·¨ÅÐ¶Ï try { result = eval(result); return result; } catch (Error) { alert("±§Ç¸£¡Óï¾äÎÞ·¨Ö´ÐÐת»¯¡£×¢ÒâÓï·¨ºÍƴд¡£"); return; } }else{ alert("Çë¼ì²éÊý¾ÝÀàÐÍת»»Óï¾äµÄ¸ñʽ¼°Óï·¨£¡"); } } ÓйØÊý¾Ýת»»·½·¨µÄÆäËû²âÊÔʾÀýÈçÏ£º
Àý ¾ä | ½á ¹û |
---|---|
parseInt('1234') | 1234 |
parseInt('1234.00') | 1234 |
parseInt('1234abc') | 1234 |
parseInt('abc1234') | undefined(ת»»Ê§°Ü) |
parseFloat('1234.123') | 1234.123 |
parseFloat('1234.123a') | 1234.123 |
parseFloat('a1234.123') | NaN |
Number('1234.123') | 1234.123 |
Number('1234.123aa') | NaN |
String(eval('12+10')) | 22 |
Boolean('0'),Boolean('567'),Boolean(567) | true |
Boolean(null),Boolean(false),Boolean(0),Boolean(''),Boolean() | false |
this.toString() | [object] |
(typeof(this)).toString() | object |
eval('12+34') | 46 |
eval('12+34')+'' | 46 |
eval('12+34')*1.0 | 46 |
typeof(eval('12+34')*1.0) | number |
typeof(eval('12+34')+'') | string |
×¢£º²âÊÔʱµÄ»·¾³ÊÇ vs2008£¬ie8...£¬ÊÇÔÚÒ³ÃæÉÏÊäÈëµÄÓï¾ä£¬jsÀïÓÃeval´¦ÀíÉϱíÖÐ×óÀ¸µÄת»»Àý¾ä¡£
ʹÓÃʱ»òÐíÐèÒªÐ޸ķûºÅµÈ¡£
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ