zoukankan      html  css  js  c++  java
  • js 去掉空格

    写成类的方法格式如下:(str.trim();)
    <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>
    写成函数可以这样:(trim(str))
    <script type="text/javascript">
    function trim(str){ //删除左右两端的空格
    return str.replace(/(^s*)|(s*$)/g, "");
    }
    function ltrim(str){ //删除左边的空格
    return str.replace(/(^s*)/g,"");
    }
    function rtrim(str){ //删除右边的空格
    return str.replace(/(s*$)/g,"");
    }
    </script>
  • 相关阅读:
    day74作业
    day072作业
    Serializer类
    day067作业
    day066作业
    day065作业
    django
    jQuery
    JavaScript
    mediaplayer state
  • 原文地址:https://www.cnblogs.com/wyy226wyj/p/3653733.html
Copyright © 2011-2022 走看看