function trimStr(str){ return str.replace(/(^\s*)|(\s*$)/g,""); } 用的时候就是直接 var 变量=trimStr(需要去空格的字符串); 相关文章: