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

javascriptÖÐreplace()


javascriptÖÐreplace()
   ÔÚjavascriptÖУ¬StringµÄº¯Êýreplace()¼òֱ̫ÈÃÈËϲ°®ÁË¡£ËüÁé»î¶øÇ¿´óµÄ×Ö·ûÌæ»»´¦ÀíÄÜÁ¦£¬ÈÃÎÒ²»½ûÏëÏò´ó¼Ò½éÉÜËü¡£
¡¡¡¡replace()×î¼òµ¥µÄËãÊÇÄÜÁ¦¾ÍÊǼòµ¥µÄ×Ö·ûÌæ»»¡£Ê¾Àý´úÂëÈçÏ£º
<script language="javascript">
 var strM = "javascript is a good script language";
 //ÔÚ´ËÎÒÏ뽫×ÖĸaÌæ»»³É×ÖĸA
 alert(strM.replace("a","A"));
</script>
¡¡¡¡ÎÒÏë´ó¼ÒÔËÐкó¿ÉÒÔ¿´µ½½á¹û£¬ËüÖ»Ìæ»»ÁËÊ××Öĸ¡£µ«Èç¹û¼ÓÉÏÕýÔò±í´ïʽ½á¹û¾Í²»Ò»ÑùÁË£¡ºÇºÇ£¬Ã»´í¡£replace()Ö§³ÖÕýÔò±í´ïʽ£¬Ëü¿ÉÒÔ°´ÕÕÕýÔò±í´ïʽµÄ¹æÔòÆ¥Åä×Ö·û»ò×Ö·û´®£¬È»ºó¸øÓèÌæ»»£¡
<script language="javascript">
 var strM = "javascript is a good script language";
 //ÔÚ´ËÎÒÏ뽫×ÖĸaÌæ»»³É×ÖĸA
alert(strM.replace(/a/,"A"));
 </script>
¡¡¡¡ºÇºÇ£¬ÄúÒ»¶¨·¢ÏÖÁË¡£ÕâÑù»¹ÊÇÖ»Ìæ»»Á˵ÚÒ»¸ö×Öĸa¡£Èç¹ûÄúÊìϤÕýÔò£¬ÄÇÕâ¾ÍÄѲ»×¡Äú¡£ÉÔ¼ÓÐ޸ľÍOKÁË¡£
<script language="javascript">
var strM = "javascript is a good script language";
 //Ôڴ˽«×ÖĸaÈ«²¿Ìæ»»³É×ÖĸA
alert(strM.replace(/a/g,"A"));
</script>
¡¡¡¡»¹¿ÉÒÔÕâÑù£¬¿´¿´Ð§¹û£¡
<script language="javascript">
 var strM = "javascript is a good script language";
 alert(strM.replace(/(javascript)\s*(is)/g,"$1 $2 fun. it $2"));
</script>
¡¡¡¡ÎÒÕâ¶ù¾ÙµÄÀý×Ó¶¼ÊǺܼòµ¥µÄÓ¦Óã¬replace()Ôڴ˵ãÉÏÓëÄúʹÓÃÕýÔò±í´ïʽµÄÄÜÁ¦³ÉÕý±È¡£ÄúÕýÔò±í´ïʽԽǿ£¬ºÇºÇ£¬ÄÇÄú¾Í»áÔ½·è¿ñµÄ°®ÉÏËü¡£
¡¡¡¡µ±È»£¬ÎÒÕâ¶ùÍƼöreplace()µÄÔ­Òò²¢²»ÒòΪËüÄÜÓëÕýÔò±í´ïʽºÏ×÷£¬¶øÔÚÓÚËü»¹ÄÜÓ뺯Êý½øÐкÏ×÷£¬·¢»Ó³öÇ¿´óµÄ¹¦ÄÜ¡£
¡¡¡¡ÏÈ¿´¿´¼òµ¥Àý×Ó£º½«ËùÓе¥´ÊÊ××Öĸ»»³É´óд¡£
<script language="javascript">
 var strM = "javascript is a good script language";
 function change(word)
{
¡¡return word.indexOf(0).toUpperCase()+word.substring(1);
}
 alert(strM.replace(/\b\w+\b/g,change));
</script>
¡¡¡¡ÓÉÉÏ¿ÉÖª£¬µ±ÕýÔò±í´ïʽÓÐ"g"±ê־ʱ£¬´ú±í½«´¦ÀíÕû¸ö×Ö·û´®£¬¼´º¯ÊýchangeµÄ±ä»»½«Ó¦ÓÃÓÚËùÓÐÆ¥ÅäµÄ¶ÔÏ󡣶ø¸Ãº¯ÊýÓÐÈý¸ö»ò¸ü¶à²ÎÊý£¬¾ßÌå¸öÊýÊÓÕýÔò±í´ïʽ¶ø¶¨¡£
¡¡¡¡ÓÐÁ˺¯ÊýÓëÕýÔò±í´ïʽµÄÅäºÏ£¬


Ïà¹ØÎĵµ£º

½â¾öFirefox ÏÂF5ºÍIEÏÂF5 ²»Ò»ÖµÄjavascript ½Å±¾.

½â¾öFirefox ÏÂF5ºÍIEÏÂF5 ²»Ò»ÖµÄjavascript ½Å±¾.
var check=function(e)
 {
  e=e||window.event;
  //alert(e.which||e.keyCode);
  if((e.which||e.keyCode)==116)
  {
   if(e.preventDefault)
   { e.preventDefault();}
&nb ......

javascript»ù´¡ÖªÊ¶¡¾×îÏ꾡¡¿

1 ´´½¨½Å±¾¿é
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script> 
2 Òþ²Ø½Å±¾´úÂë
1: <script language=”JavaScript”>
2: <!--
3: document.write(&ldquo ......

JavaScript µÄ¼Ì³Ð»úÖÆ

      ¼Ì³Ð»úÖÆ£¬Ëµµ½¼Ì³Ð£¬¾ÍÒªÏëµ½´Ó»ùÀ࿪ʼ£¬µ«ÊÇJavaScriptÖеÄÀàÓÐÁ½´óÀࣺһ£¬ÄÚǶµÄ£»¶þ£¬Óû§×Ô¶¨Ò壻һ°ãÇ°Õß²»»á±»ÓÃÀ´×ö»ùÀ࣬ԭÒòÊÇΪÁ˱£ÕÏjsµÄ°²È«¡£µ«ÊÇÎÒÃÇ¿ÉÒÔͨ¹ýprototypeÀ´¶Ô»ùÀà½øÐÐÀ©³ä£¬Ôö¼ÓÎÒÃÇÏëÒªµÄÊôÐԺͷ½·¨¡£ÒÔÏÂÊÇ×Ô¼º¶Ô¼Ì³ÐµÄ¼¸ÖÖ·½Ê½µÄÀí½â¡£
1>  ¶ÔÏó ......

javascriptÊý¾ÝÀàÐÍת»»

parseFloat ת»»³É¸¡µãÊý
parseInt ת»»³ÉÕûÊý.
ÕâÁ½¸öº¯Êý¶¼ÓÐЩÈÝ´íÐÔµÄ,±ÈÈç"123abc"»á±ä³É123.
Èç¹ûÂ¥Ö÷Ï£Íû¸ü׼ȷһЩ,Æäʵ¿ÉÒÔÅжÏÒ»ÏÂ,È»ºóÓÃeval,ÏñÕâÑù
²»¹ýÒ²¿ÉÒÔʹÓÃÕâÑùµÄ·½·¨:
var a = "234" ;
a = a.replace(/(^[\\s]*)|([\\s]*$)/g, "");
if( a !="" && !isNaN( a ) )
{//Èç¹ûÊÇÊý×Ö
a = e ......

dz̸JavaScriptµÄArray¶ÔÏó

        Array×÷ΪJavaScriptµÄÒ»¸öÄÚÖöÔÏó£¬ÓÐ×ÅÇ¿´óµÄ¹¦ÄÜ£»Ïà¶ÔÓÚÆäËûÄÚÖöÔÏóÀ´Ëµ£¬ËûÓÐ×ÅÌØÊâµÄÓ÷¨£¬ÏÂÃæ¶Ô˵˵×Ô¼º¶ÔArrayµÄÓ÷¨µÄÒ»¸öС×ܽ᣺
1>ÓÃ;һ£ºÊý×é
    Êý×é×î´ó´æ´¢Êý¾ÝΪËÄÊ®¶àÒÚ¸ö£¬Õâ¸ö¿Õ¼ä×ã¹»ÓÃÁË£¬ËùÒÔÊý×é¿ÉÒÔËæ±ãµÄÀ©ÈÝ¡£ÏÂÃæ¶Ô³£Óõ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ