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µÄStringÀàÄÚÖú¯Êýreplace(regexp, newString)º¯ÊýÌṩÁË×Ö·û´®Ìæ»»¹¦ÄÜ£¬´Óº¯ÊýÔÐÍÉÏ¿ÉÒÔ¿´³öÖ§³Ö Regular Exp¡£´Ëº¯Êý¹¦Äܷdz£ÊµÓ㬵«Ò²Óм¸¸öµØ·½Óеã»ìÏý£¬ÏÂÃæÍ¨¹ýʵ¼ÊµÄÀý×ÓÀ´ËµÃ÷£º
±ÈÈçÎÒÃÇÏÖÔÚÒªÕë¶Ô´®
var src="<a href="http://xx.com/a/2010 ......
ÔÎijö´¦: http://www.dnew.cn/post/196.htm
ÏÈ¿´ÏÂÏÂÃæ¼¸ÖÖд·¨
1.function f(x){return x*x;};f(x);
2.(function(x){return x*x;})(x);
3.(function(x){return x*x;}(x));
µÚÒ»ÖÖÎÒÃÇÓ¦¸Ã¶¼ºÜÊìϤÁË£¬ÕâÊÇÎÒÃǾ³£Ê¹ÓõÄд·¨¡£µÚ¶þµÚÈýÖÖ¶¼ÊÇÄäÃûº¯ÊýµÄд·¨¡£
------------------------------------------------ ......
³ýÁËÓÃgetElementByTagName µÄÁíÒ»ÖÖ»ñÈ¡¶ÔÏ󼯺ϵķ½·¨
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" conte ......
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дÔÚº¯ÊýÀïÃæ
function loadscript(url) {
document.write('<scr' + 'ipt type="text/javascript" src"' + url + '"><\/scr' + 'ipt>'>)
}
Ôڳɹ¦µÄÕýÔò±í´ïʽ²éÕÒÍê³É֮ǰ£¬ÆäÊôÐÔֵΪ undefined¡£
²»Òª½«È«¾Ö RegExp ¶ÔÏóÓë ÕýÔò±í´ïʽ
¶ÔÏó»ìÏý¡£¾¡¹ÜÌýÆðÀ´Ï ......