写一个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+$/,"");
}
原文地址:https://www.cnblogs.com/lcx90/p/4873792.html