JavaScript ×Ö·û´®×ª»»Êý×Ö
·½·¨Ö÷ÒªÓÐÈýÖÖ
ת»»º¯Êý¡¢Ç¿ÖÆÀàÐÍת»»¡¢ÀûÓÃjs±äÁ¿ÈõÀàÐÍת»»¡£
1. ת»»º¯Êý
jsÌṩÁËparseInt()ºÍparseFloat()Á½¸öת»»º¯Êý¡£Ç°Õß°Ñֵת»»³ÉÕûÊý£¬ºóÕß°Ñֵת»»³É¸¡µãÊý¡£Ö»ÓжÔStringÀàÐ͵÷ÓÃÕâЩ·½·¨£¬ÕâÁ½¸öº¯Êý²ÅÄÜÕýÈ·ÔËÐУ»¶ÔÆäËûÀàÐÍ·µ»ØµÄ¶¼ÊÇNaN(Not a Number)¡£
ÔÚÅжÏ×Ö·û´®ÊÇ·ñÊÇÊý×Öֵǰ£¬parseInt()ºÍparseFloat()¶¼»á×Ðϸ·ÖÎö¸Ã×Ö·û´®¡£parseInt()·½·¨Ê×ÏȲ鿴λÖÃ0´¦µÄ×Ö·û£¬ÅжÏËüÊÇ·ñÊǸöÓÐЧÊý×Ö£»Èç¹û²»ÊÇ£¬¸Ã·½·¨½«·µ»ØNaN£¬²»ÔÙ¼ÌÐøÖ´ÐÐÆäËû²Ù×÷¡£µ«Èç¹û¸Ã×Ö·ûÊÇÓÐЧÊý×Ö£¬¸Ã·½·¨½«²é¿´Î»ÖÃ1´¦µÄ×Ö·û£¬½øÐÐͬÑùµÄ²âÊÔ¡£ÕâÒ»¹ý³Ì½«³ÖÐøµ½·¢ÏÖ·ÇÓÐЧÊý×ÖµÄ×Ö·ûΪֹ£¬´ËʱparseInt()½«°Ñ¸Ã×Ö·û֮ǰµÄ×Ö·û´®×ª»»³ÉÊý×Ö¡£
ÀýÈ磬Èç¹ûÒª°Ñ×Ö·û´® "1234blue "ת»»³ÉÕûÊý£¬ÄÇôparseInt()½«·µ»Ø1234£¬ÒòΪµ±Ëü¼ì²âµ½×Ö·ûbʱ£¬¾Í»áÍ£Ö¹¼ì²â¹ý³Ì¡£×Ö·û´®Öаüº¬µÄÊý×Ö×ÖÃæÁ¿»á±»Õýȷת»»ÎªÊý×Ö£¬Òò´Ë×Ö·û´® "0xA "»á±»Õýȷת»»ÎªÊý×Ö10¡£²»¹ý£¬×Ö·û´® "22.5 "½«±»×ª»»³É22£¬ÒòΪ¶ÔÓÚÕûÊýÀ´Ëµ£¬Ð¡ÊýµãÊÇÎÞЧ×Ö·û¡£Ò»Ð©Ê¾ÀýÈçÏ£º
parseInt("1234blue"); //returns 1234
parseInt("0xA"); //returns 10
parseInt("22.5"); //returns 22
parseInt("blue"); //returns NaN
parseInt()·½·¨»¹Óлùģʽ£¬¿ÉÒ԰Ѷþ½øÖÆ¡¢°Ë½øÖÆ¡¢Ê®Áù½øÖÆ»òÆäËûÈκνøÖƵÄ×Ö·û´®×ª»»³ÉÕûÊý¡£»ùÊÇÓÉparseInt()·½·¨µÄµÚ¶þ¸ö²ÎÊýÖ¸¶¨µÄ£¬ËùÒÔÒª½âÎöÊ®Áù½øÖƵÄÖµ£¬ÐèÈçϵ÷ÓÃparseInt()·½·¨£º
parseInt("AF", 16); //returns 175
µ±È»£¬¶Ô¶þ½øÖÆ¡¢°Ë½øÖÆ£¬ÉõÖÁÊ®½øÖÆ£¨Ä¬ÈÏģʽ£©£¬¶¼¿ÉÒÔÕâÑùµ÷ÓÃparseInt()·½·¨£º
parseInt("10", 2); //returns 2
parseInt("10", 8); //returns 8
parseInt("10", 10); //returns 10
Èç¹ûÊ®½øÖÆÊý°üº¬Ç°µ¼0£¬ÄÇô×îºÃ²ÉÓûùÊý10£¬ÕâÑù²Å²»»áÒâÍâµØµÃµ½°Ë½øÖƵÄÖµ¡£ÀýÈ磺
parseInt("010"); //returns 8
parseInt("010", 8); //returns 8
parseInt("010", 10); //returns 10
ÔÚÕâ¶Î´úÂëÖУ¬Á½ÐдúÂ붼°Ñ×Ö·û´®
Ïà¹ØÎĵµ£º
http://blog.csdn.net/mouyong/archive/2009/12/07/4959741.aspx
µÚ4Õ º¯Êý
JavaScriptÖÐ×îºÃµÄÌØÐÔ¾ÍÊÇËü¶Ôº¯ÊýµÄʵÏÖ¡£Ëü¼¸ºõÎÞËù²»ÄÜ¡£µ«ÊÇ£¬Ïë±ØÄãÒ²ÄÜÔ¤Áϵ½£¬º¯ÊýÔÚJavaScriptÀïÒ²²¢·ÇÍòÄÜÒ©¡£
º¯Êý°üº¬Ò»×éÓï¾ä£¬ËüÃÇÊÇJavaScriptµÄ»ù´¡Ä£¿éµ¥Ôª£¬ÓÃÓÚ´úÂ븴Óá¢ÐÅÏ¢Òþ²ØºÍ×éºÏµ÷Ó᣺¯ÊýÓÃÓÚÖ¸¶¨¶ ......
http://blog.csdn.net/mouyong/archive/2009/12/07/4959827.aspx
4.9 ×÷ÓÃÓò
ÔÚ±à³ÌÓïÑÔÖУ¬×÷ÓÃÓò¿ØÖÆ×űäÁ¿Óë²ÎÊýµÄ¿É¼ûÐÔ¼°ÉúÃüÖÜÆÚ¡£¶Ô³ÌÐòÔ±À´ËµÕâÊÇÒ»¸öÖØÒªµÄ°ïÖú£¬ÒòΪËü¼õÉÙÁËÃû³Æ³åÍ»£¬²¢ÇÒÌṩÁË×Ô¶¯ÄÚ´æ¹ÜÀí¡£
´ó¶àÊýʹÓÃCÓïÑÔÓï·¨µÄÓïÑÔ¶¼ÓµÓп鼶×÷ÓÃÓò¡£ÔÚÒ»¸ö´úÂë¿éÖУ¨À¨ÔÚÒ»¶Ô»¨À¨ºÅ ......
ת×Ô£ºhttp://news.csdn.net/a/20100217/217053.html
JavaScript ¿ÉËãÊÇÊÀ½çÉÏ×îÁ÷Ðеıà³ÌÓïÑÔ£¬ËüÔø±» Web ¿ª·¢Éè¼ÆʦÌùÉÏجÃεıêÇ©£¬ËäÈ»ÕæÕýµÄجÃÎÆäʵÊÇ DOM API£¬Õâ¸ö±»´óÁ¿µÄ¿ª·¢ÓëÉè¼ÆʦËæÊÖÄéÀ´ÔöÇ¿ËûÃÇµÄ Web Ç°¶ËµÄ½Å±¾ÓïÑÔ£¬Èç½ñÔ½À´Ô½±»ÖØÊÓ£¬ËäÔòÈç´Ë£¬JavaScript ÈÔȻӵÓкܶàÈÃÈ˷ѽâµÄ¶«Î÷¡£
1. ËüÒÔ J ......
Javascript code prettifier
Javascript ´úÂëÃÀÈÝʦ
°²×°Ê¹ÓÃ
ÏÂÔØ Îļþ
ÔÚÄãµÄÎļþÖаüº¬Õâ¶ùµÄ½Å±¾ºÍÑùʽ±í(ÄãÒª±£Ö¤Õâ¶ùµÄ css ºÍ js Îļþ°´ÔÚÄãµÄ·þÎñÆ÷ÉÏ, ²¢ÇÒµ÷ÕûÔÚ script ºÍ link±êÇ©ÖеÄ·¾¶)
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" sr ......