var str = " 1 sa s "; str = str.replace(/\s/g, ''); 转载于:https://www.cnblogs.com/sooooogiotto/p/10912215.html