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));
}

 這式另外一種方式,能夠去除字符串中全部的空格。spa

$(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())
})