久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      用JavaScript實(shí)現(xiàn)全局替換,解決$等特殊符號(hào)的難題[

      感謝海浪提供的正則,原貼請參見:
      http://www.iecn.net/bbs/view/106503.html

      因?yàn)橐鰝€(gè)模板替換的東西,里面的變量采用${MyName}這種格式的命名方式。在進(jìn)行全局替換時(shí),遇到兩個(gè)難點(diǎn):
      1.要么無法替換掉$等特殊符號(hào)
      2.要么無法忽略大小寫

      在海浪有幫助下,終于有了最佳實(shí)現(xiàn)方式:)

      最佳實(shí)現(xiàn)方式:

      復(fù)制代碼 代碼如下:
      <script type=”text/javascript”> 
      String.prototype.replaceAll = stringReplaceAll; 

      function stringReplaceAll(AFindText,ARepText){ 
       var raRegExp = new RegExp(AFindText.replace(/([()[]{}^$+-*?.”‘|/\])/g,”\$1″),”ig”); 
       return this.replace(raRegExp,ARepText); 

      var ssString=”www.cnlei.com;www.CnLei.net;www.cnlei.org”; 
      alert(ssString.replaceAll(“cnlei”,”iecn”)); 

      ssString=”www.${MyName}.com;www.${MyName}.net;www.${MyName}.org”; 
      alert(ssString.replaceAll(“${MyName}”,”cnlei”)); 

      ssString=”www.{MyName}.com;www.{MyName}.net;www.{MyName}.org”; 
      alert(ssString.replaceAll(“{MyName}”,”cnlei”)); 
      </script> 

      以前使用方法一:(可實(shí)現(xiàn)忽略大小,但無法實(shí)現(xiàn)特殊符號(hào)的替換)

      復(fù)制代碼 代碼如下:
      <script type=”text/javascript”> 
      String.prototype.replaceString = stringReplaceAll; 

      function stringReplaceAll(AFindText,ARepText){ 
       var raRegExp = new RegExp(AFindText,”ig”); 
       return this.replace(raRegExp,ARepText); 

      var ssString=”www.cnlei.com;www.CnLei.net;www.cnlei.org”; 
      alert(ssString.replaceString(“cnlei”,”iecn”)); 

      ssString=”www.${MyName}.com;www.${MyName}.net;www.${MyName}.org”; 
      alert(ssString.replaceString(“${MyName}”,”cnlei”)); 

      ssString=”www.{MyName}.com;www.{MyName}.net;www.{MyName}.org”; 
      alert(ssString.replaceString(“{MyName}”,”cnlei”)); 
      </script> 

      以前使用的方式二:(可替換特殊符號(hào)$等,但無法忽略大小寫)

      復(fù)制代碼 代碼如下:
      <script type=”text/javascript”> 
      String.prototype.replaceString = function(s1,s2){ 
      this.str=this; 
      if(s1.length==0)return this.str; 
       var idx=this.str.indexOf(s1); 
       while(idx>=0){ 
       this.str=this.str.substring(0, idx)+s2+this.str.substr(idx+s1.length); 
       idx=this.str.indexOf(s1); 
       } 
       return this.str; 

      var ssString=”www.cnlei.com;www.CnLei.net;www.cnlei.org”; 
      alert(ssString.replaceString(“cnlei”,”iecn”)); 

      ssString=”www.${MyName}.com;www.${MyName}.net;www.${MyName}.org”; 
      alert(ssString.replaceString(“${MyName}”,”cnlei”)); 

      ssString=”www.{MyName}.com;www.{MyName}.net;www.{MyName}.org”; 
      alert(ssString.replaceString(“{MyName}”,”cnlei”)); 
      </script>

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)