1 function trim(str){//去除字符串两端空格 2 var start,end; 3 start = 0; 4 end = str.length - 1; 5 6 while(start<=end && str.charAt(start)==" "){ 7 start++; 8 } 9 while(start<=end && str.charAt(end)==" "){ 10 end--; 11 } 12 return str.substring(start,end+1); 13 }