Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javascriptÕýÔò±í´ïʽʵÏÖtrim()ÒÉ»ó

ÕýÔÚ¿´¡¡javascript¸ß¼¶³ÌÐòÉè¼Æ¡¡,ÆäÖйØÓÚ·Ö×éÀïÃæµÄÒ»¾ä´úÂë²»ÊÇÌ«Àí½â:
ͨ¹ýÅäºÏʹÓÃString¶ÔÏóµÄreplace()·½·¨¼°·´ÏòÒýÓ㬾ͿÉÒÔ¶¨Òå×Ô¼ºµÄtrim()·½·¨:
String.prototype.trim = function() {
var reExtraSpace = /^\s+(.*?)\s+$/;
return this.replace(reExtraSpace,"$1");
}
 
Ò»¿ªÊ¼ÔõôҲ²»Àí½â trim() ·½·¨ÊÇÔõôÆð×÷ÓõÄ
var sTest = " this is a test ";
alert("[" + sTest + "]"); //outputs " [ this is a test ] "
alert("[" + sTest.trim() + "]"); outputs " [this is a test] " 
ºóÀ´²éÁËһϡ¡javascript ÀïÃæ StringObject µÄ replace(regexp,replacement)
·½·¨µÄµÚ¶þ¸ö²ÎÊýreplacementÀïÃæµÄ"$"ÌØÊ⺬Ò壺
$n±íʾµÚ n ¸ö×Ó±í´ïʽ , Ò²¾ÍÊÇ .*?
Ô­À´·Ö×é¾ÍÊÇÕýÔò±í´ïʽµÄ×Ó±í´ïʽ


Ïà¹ØÎĵµ£º

javascript²Ù×÷divÖеÄmarginTop

ÔÚjavascript¿ØÖÆdivÖ®¼äµÄÍâ±ß¾àʱ£¬´úÂëдµ½
document.getElementById("").style.marginTop=20;
Õâ¸öÔÚIEä¯ÀÀÆ÷ÖпÉÒÔ£¬µ«ÊÇÔÚchromeÖоͲ»ÐУ¬Õâ¸öÎÊÌâÊÇÓ¦¸Ã
document.getElementById("").style.marginTop="20px";
¸÷¸öä¯ÀÀÆ÷Öв»Í¬µÄÎÊÌâÒªÇ󲻵ȶԴý£¬ÕâЩÌìѧÁËdiv+cssÔÚÉèÖø÷¸öä¯ÀÀÆ÷ÊDz»Í¬µÄÅäÖã¬ÒªÕë¶Ôÿ¸ö ......

String.prototypeʵÏÖµÄһЩjavascriptº¯Êý


//String.prototypeʹÓà   
  
//ÅúÁ¿Ìæ»»£¬±ÈÈ磺str.ReplaceAll([/a/g,/b/g,/c/g],["aaa","bbb","ccc"])   
String.prototype.ReplaceAll=function (A,B) {   
    var C=this;   
    for(var i ......

JavaScriptµÄº¯Êý


º¯Êý
    ¼´Ê¹º¯ÊýȷʵÓзµ»ØÖµ£¬Ò²²»±ØÃ÷È·µØÉùÃ÷Ëü¡£¸Ãº¯ÊýÖ»ÐèҪʹÓÃreturnÔËËã·ûºó¸úÒª·µ»ØµÄÖµ¼´¿É¡£
    Àý£º
        function sum(iNum1, iNum2)
        {
           ......

¹ØÓÚJavaScriptÖеÄprompt·½·¨


¶¨ÒåºÍÓ÷¨
prompt() ·½·¨ÓÃÓÚÏÔʾ¿ÉÌáʾÓû§½øÐÐÊäÈëµÄ¶Ô»°¿ò¡£
Óï·¨
prompt(text,defaultText)
²ÎÊýÃèÊö
text
¿ÉÑ¡¡£ÒªÔÚ¶Ô»°¿òÖÐÏÔʾµÄ´¿Îı¾£¨¶ø²»ÊÇ HTML ¸ñʽµÄÎı¾£©¡£
defaultText
¿ÉÑ¡¡£Ä¬ÈϵÄÊäÈëÎı¾¡£
˵Ã÷
Èç¹ûÓû§µ¥»÷Ìáʾ¿òµÄÈ¡Ïû°´Å¥£¬Ôò·µ»Ø null¡£Èç¹ûÓû§µ¥»÷È·Èϰ´Å¥£¬Ôò·µ»ØÊäÈë×ֶε±Ç°Ï ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ