茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    Javascript 5種方法實(shí)現(xiàn)過濾刪除前后所有空格
    來源:易賢網(wǎng) 閱讀:900 次 日期:2016-07-12 16:11:12
    溫馨提示:易賢網(wǎng)小編為您整理了“Javascript 5種方法實(shí)現(xiàn)過濾刪除前后所有空格”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹Javascript 5種過濾刪除前后所有空格的方法,比較實(shí)用,需要的朋友可以參考下。

    第一種:循環(huán)檢查替換

    //供使用者調(diào)用 

    function trim(s){ 

      return trimRight(trimLeft(s)); 

    //去掉左邊的空白 

    function trimLeft(s){ 

      if(s == null) { 

        return ""; 

      } 

      var whitespace = new String(" \t\n\r"); 

      var str = new String(s); 

      if (whitespace.indexOf(str.charAt(0)) != -1) { 

        var j=0, i = str.length; 

        while (j < i && whitespace.indexOf(str.charAt(j)) != -1){ 

          j++; 

        } 

        str = str.substring(j, i); 

      } 

      return str; 

    //去掉右邊的空白 www.jb51.net 

    function trimRight(s){ 

      if(s == null) return ""; 

      var whitespace = new String(" \t\n\r"); 

      var str = new String(s); 

      if (whitespace.indexOf(str.charAt(str.length-1)) != -1){ 

        var i = str.length - 1; 

        while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1){ 

          i--; 

        } 

        str = str.substring(0, i+1); 

      } 

      return str; 

    }     

    第二種:正則替換

    <SCRIPT LANGUAGE="JavaScript"> 

    <!-- 

    String.prototype.Trim = function() 

    return this.replace(/(^\s*)|(\s*$)/g, ""); 

    String.prototype.LTrim = function() 

    return this.replace(/(^\s*)/g, ""); 

    String.prototype.RTrim = function() 

    return this.replace(/(\s*$)/g, ""); 

    //--> 

    </SCRIPT>

    //去左空格;

    function ltrim(s){

      return s.replace(/(^\s*)/g, "");

    }

    //去右空格;

    function rtrim(s){

      return s.replace(/(\s*$)/g, "");

    }

    //去左右空格;

    function trim(s){

      return s.replace(/(^\s*)|(\s*$)/g, "");

    }

    第三種:使用jquery

    $.trim(str)

    jquery內(nèi)部實(shí)現(xiàn)為:

    function trim(str){  

      return str.replace(/^(\s|\u00A0)+/,'').replace(/(\s|\u00A0)+$/,'');  

    }

    第四種:使用motools

    function trim(str){  

      return str.replace(/^(\s|\xA0)+|(\s|\xA0)+$/g, '');  

    }

    第五種:裁剪字符串方式

    function trim(str){  

      str = str.replace(/^(\s|\u00A0)+/,'');  

      for(var i=str.length-1; i>=0; i--){  

        if(/\S/.test(str.charAt(i))){  

          str = str.substring(0, i+1);  

          break;  

        }  

      }  

      return str;  

    }

    -----------------------------------------------------------------------------------

    //----------------------------------------------------------

    //   去掉字符串前后的空格

    //  返回值:

    //  去除空格后的字符串

    //----------------------------------------------------------

    function trim(param) {

      if ((vRet = param) == '') { return vRet; }

      while (true) {

        if (vRet.indexOf (' ') == 0) {

          vRet = vRet.substring(1, parseInt(vRet.length));

        } else if ((parseInt(vRet.length) != 0) && (vRet.lastIndexOf (' ') == parseInt(vRet.length) - 1)) {

          vRet = vRet.substring(0, parseInt(vRet.length) - 1);

        } else {

          return vRet;

        }

      }

    }

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:Javascript 5種方法實(shí)現(xiàn)過濾刪除前后所有空格
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)