1、用jquery的trim()方法,$.trim(str)就可以了。
2、String扩展:
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, "");
}

本文详细介绍了如何使用jQuery的trim()方法去除字符串两端的空格,并提供了String扩展方法来进一步实现左去空格和右去空格的功能。

被折叠的 条评论
为什么被折叠?



