方法一: function KillSpace(x) { while((x.length > 0) && (x.charAt(0) == ' ')) x = x.substring(1, x.length); while((x.length > 0) && (x.charAt(x.length - 1) == ' ')) x = x.substring(0, x.length - 1); return x; } 方法二: function killSpace(value) { for(i=0;i<value.length;i++) if(value.charAt(0)==" ") value=value.substring(1); else break; for(i=value.length-1;i>0;i--) if(value.charAt(value.length-1)==" ") value=value.substring(0,value.length-2); else break; return value; }