javascript怎样去掉字符串左右空格?

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 上午.

:cry: 恩,挺不错的,方老师,您的学员要是有找工作的,就来有啦人才网, http://www.uolov.com

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

*
请输入图片中的字符以验证你并非垃圾机器人. 点击图片收听验证码的语音版.
点击这里收听此验证码的语音版本