JavaScript ×Ö·û´®×ª»»Êý×Ö(תÔØ)
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
ÔÚÕâ¶Î´úÂëÖУ¬Á½ÐдúÂ붼°Ñ×Ö·û´
Ïà¹ØÎĵµ£º
JavaScriptÊÇ»ùÓÚ¶ÔÏóµÄ£¬ÈκÎÔªËض¼¿ÉÒÔ¿´³É¶ÔÏó¡£È»¶ø£¬ÀàÐͺͶÔÏóÊDz»Í¬µÄ¡£±¾ÎÄÖУ¬ÎÒÃdzýÁËÌÖÂÛÀàÐͺͶÔÏóµÄһЩÌصãÖ®Í⣬¸üÖØÒªµÄÊÇÑо¿ÈçºÎд³öºÃµÄ²¢ÇÒÀûÓÚÖØÓõÄÀàÐÍ¡£±Ï¾¹£¬JavaScriptÕâÖÖÁ÷ÐеĽű¾ÓïÑÔÈç¹ûÄܹ»½øÐÐÁ¼ºÃµÄ·â×°£¬²¢ÐγÉÒ»¸öÅÓ´óµÄÀàÐͿ⣬¶ÔÓÚÖØÓÃÊǷdz£ÓÐÒâÒåµÄ¡£
ÍøÉ϶ÔÓÚprototypeµÄÎÄÕ弆 ......
1. document.write( " "); Êä³öÓï¾ä
2.JSÖеÄ×¢ÊÍΪ//
3.´«Í³µÄHTMLÎĵµË³ÐòÊÇ:document- >html- >(head,body)
4.Ò»¸öä¯ÀÀÆ÷´°¿ÚÖеÄDOM˳ÐòÊÇ:window- >(navigator,screen,history,location,document)
5.µÃµ½±íµ¥ÖÐÔªËصÄÃû³ÆºÍÖµ:document.getElementById( "±íµ¥ÖÐÔªËصÄID號 ").name(»òvalue)
6.Ò ......
JavaScriptµÄä¯ÀÀÆ÷¶ÔÏóÏê½â
Ò»¡¢ä¯ÀÀÆ÷¶ÔÏó²ã´Î¼°ÆäÖ÷Òª×÷ÓÃ
¶þ¡¢Îĵµ¶ÔÏó¹¦Äܼ°Æä×÷ÓÃ
Èý¡¢·¶Àý
ʹÓÃä¯ÀÀÆ÷µÄÄÚ²¿¶ÔÏóϵͳ, ¿ÉʵÏÖÓëHTMLÎĵµ½øÐн»»¥¡£ËüµÄ×÷ÓÃÊǽ«Ïà¹ØÔªËØ×éÖ¯°ü×°ÆðÀ´£¬Ìṩ¸ø³ÌÐòÉè¼ÆÈËԱʹÓ㬴Ӷø¼õÇá±à³ÌÈ˵ÄÀͶ¯£¬Ìá¸ßÉè¼ÆWebÒ³ÃæµÄÄÜÁ¦¡£
Ò»¡¢ä¯ÀÀÆ÷¶ÔÏó²ã´Î¼°ÆäÖ ......
<mce:script type="text/javascript"><!--
document.write("<table border=1px border-color=red>"); //±í¸ñ¿ªÊ¼
for (h = 1; h <= 10; h++) {
document.write("<tr>"); //¿ªÊ¼µÚÒ»ÐÐ
for (s = 1; s <= 10; s++) {
var num = (h-1)*10+s; ......