定义String对象的一个Trim属性方法,可以这样实现这个方法:

String.prototype.Trim = function()
     {
         return this.replace(/(^\s*)|(\s*$)/g,"");
     }

可以去掉一个字符串里前后的空格,这样一个字符串的变量就可以用到这个方法。

注:允许字符串间有空格的。

String:对象名称。prototype:增加属性。Trim:属性名称。

—-2008/12/19

Tags:

Related posts

Tags: .
Home

No Comments Now!

Be the first to comment on this entry.

Leave a comment

Name(required)
Mail (required),(will not be published)
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs must be fully qualified (eg: http://hanghang.name),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.