JS trim的实现

定义

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, "");
}

使用

s=" 123123asdfasdf "
alert(s);

s=s.Trim();
alert(s);

posted @ 2013-12-26 13:53  朋友博客集  阅读(200)  评论(0编辑  收藏  举报