在提交表单的时候会需要去除字符串两边的空格,代码如下:
/*去除字符串两边空格*/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,"")}
例:str = " fsfa fasdf sfas ";
str.trim() == "fsfa fasdf sfas";
js中去除字符串两边的空格
原文地址:https://www.cnblogs.com/suhfj-825/p/8267253.html