您的位置:首页 > Web前端 > JavaScript

JS方法 -- 去除左右空格

2009-08-12 14:19 274 查看
1、去除左空格:

String.prototype.LTrim  =  function()
{
return  this.replace(/(^/s*)/g,  ""); // wipe-left

}


2、去除右空格

String.prototype.RTrim  =  function()
{
return  this.replace(/(/s*$)/g,  ""); //wipe-right

}


3、去除左右空格

String.prototype.Trim  =  function()
{
return  this.replace(/(^/s*)  |(/s*$)/g,  ""); //wipe-left-right

}


4、去除所有空格

String.prototype.TrimAll  =  function()
{
return this.replace(//s+/g,""); //wipe-all

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: