去所有空格:
str=str.replace(/\t+/g,"").replace(/\n+/g,"").replace(/\r+/g,"").replace(/\s+/g,"");
去头尾多余空格:
str=str.replace(/\t+/g,"").replace(/\n+/g,"").replace(/\r+/g,"").replace(/(^\s+)|(\s+$)/g,"");
只是去头尾空格:
function trim(str){ return str.replace(/^\s+|\s+$/g,""); }
具体问题再具体对待吧,我懂的