运用正则去除空格:
//去左空格;function lefttrim(s){ return s.replace(/(^\s*)/g, "");}//去右空格;function righttrim(s){ return s.replace(/(\s*$)/g, "");}//去左右空格;function trim(s){ return s.replace(/(^\s*)|(\s*$)/g, "");}