去除左右及所有空格

去掉左右空格

function trim(str){ 

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

}

 

去掉所有空格

function trim(str, true){ 

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

}

posted on 2017-03-09 14:23  vsmart  阅读(123)  评论(0编辑  收藏  举报