var msg=' h e llo ';不要给内置类型随便写方法。msg.replace('^\s+'/g,'').replace('\s+$'/g,'')//将字符串两端的空字符串去掉我们常规来说写两个正则表达比较准确一点msg.replace('^\s+|\s+$'/g,'');