javascript去空格,绝对好用
    //调用:
var s="  dss  ";
s=trim(s);
alert(s)
//调用以下程序
function trim(s){
    s=removebeforechar(s);
    s=removeafterchar(s);
    return s;
}
//去前空格
 function removebeforechar(t)
 { 
  if(t.charCodeAt(0)==32 || t.charCodeAt(0)==12288)
  { 
    t=t.slice(1,t.length);
    return   removebeforechar(t);
  } 
  else
   {
     return t; 
   }
 }
//去后空格
function removeafterchar(t)
{
  if(t.charCodeAt(t.length-1)==32 || t.charCodeAt(t.length-1)==12288)
  { 
    t=t.slice(0,t.length-1);
    return   removeafterchar(t);
  } 
  else
   { 
     return t; 
   }
}