javascript 实现TRIM功能 去掉字符串左右空格函数
<SCRIPT LANGUAGE="JavaScript"> // Trim() , Ltrim() , RTrim() String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.LTrim = function() { return this.replace(/(^\s*)/g, ""); } String.prototype.RTrim = function() { return this.replace(/(\s*$)/g, ""); } </SCRIPT> str = str.replace(/[ ]/g,""); //替换所有空格 str.replace(/(^\s*)|(\s*$)/g, ""); //去掉左右空格 str.replace(/(\s*$)/g, ""); //去掉右空格 str.replace(/(^\s*)/g, ""); //去掉左空格

1 Comment
eric-han on 九月 9, 2011 at 7:50 上午.