js去空格

function trim(str){  //删除左右两端的空格  
     return str.replace(/(^\s*)|(\s*$)/g, "");  
    } 

原文地址:https://www.cnblogs.com/Love/p/1379436.html