写一个function,清除字符串前后的空格。(兼容所有浏览器)
//重写trim方法 if(!String.prototype.trim){ String.prototype.trim = function(){ return this.replace(/^\s+/,"").replace(/\s+$/,""); } } //写fntrim去掉左右空格 function fntrim(str){ return str.replace(/^\s+/,"").replace(/\s+$/,""); }