JS中去掉字符串前后/左/右 空格
<script language=Javascript>
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 = " Trim ";
alert(str.Trim());
</script>
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 = " Trim ";
alert(str.Trim());
</script>