如下所示:String.prototype.trim=function(){var m=this.match(/^/s*(/S+(/s+/S+)*)/s*$/);return (m==null)?"":m[1];}使用:var message =" 我很好 ";message.trim();