日期:2014-05-16  浏览次数:20450 次

javascript中去掉空格
<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 - 去尾部空格