参考链接:https://www.cnblogs.com/mingforyou/p/3930638.html
第一种:原生js实现
1.去左空格
function ltrim(s){
return s.replace(/(^\s*)/g, "");
}
2.去右空格
function rtrim(s){
return s.replace(/(\s*$)/g, "");
}
3.去左右空格
function trim(s){
return s.replace(/(^\s*)|(\s*$)/g, "");
}
第二种:jquery实现
$.trim(str)