【学习篇】JavaScript去除字符串空格

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, "");
}
使用方式

var s = "     leading and trailing spaces     ";

s = s.Trim();

原文地址:https://www.cnblogs.com/jiangzhichao/p/1864754.html