请用正则实现String.trim()

  String.prototype.trim1=function(){
    return this.replace(/(^\s*)|(\s*$)/g,"");
  };

写一个function,清除字符串前后的空格(兼容所有的浏览器)

  function trim1(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }

  

猜你喜欢

转载自www.cnblogs.com/wuqilang/p/11204675.html
今日推荐