js去除字符串的前后空格 function trim(str) { if (str && typeof str === "string") { return str.replace(/^s+/,"").replace(/s+$/,""); //去除前后空白符 } } console.log('---'+trim(' jjj jjj ')+'----'); // console.log('---'+trim(' jjj jjj ')+'----');