<script language=Javascript> //自己动手为string添加Trim function String.prototype.Trim() {return this.replace(/(^\s*)|(\s*$)/g,"");} function String.prototype.Ltrim(){return this.replace(/(^\s*)/g, "");} function String.prototype.Rtrim(){return this.replace(/(\s*$)/g, "");} var str = " aaa "; alert(str.Trim()); </script>
0 - 去除前后空格; 1 - 去前导空格; 2 - 去尾部空格