去除左右及所有空格

去掉左右空格

function trim(str){ 

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

}

去掉所有空格

function trim(str, true){ 

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

}

原文地址:https://www.cnblogs.com/vsmart/p/6525495.html