js去掉字符串的空格

//去左空格;
function ltrim(s){   
    return s.replace(/(^s*)/g, "");
}
//去右空格;
function rtrim(s){ 
    return s.replace(/(s*$)/g, "");
}
//去左右空格;
function trim(s){
//s.replace(/(^s*)|(s*$)/g, "");
   return rtrim(ltrim(s));
}

 这式另一种方式,可以去除字符串中所有的空格。

$(function(){   
    $("p.class").text($("p.class").text().trim());
})
$("span.Sige_Imfine").each(function(index,element){    
    $("span.Sige_Imfine").eq(index).text(("span.Sige_Imfine").eq(index).text().trim())
})
原文地址:https://www.cnblogs.com/wuxibolgs329/p/6220378.html