javascript去掉字符串空格
String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/ig,""); } function test(){ var val = " 12 ".trim; }
function trim(value){//去掉首尾空格 return value.replace(/(^\s*)|(\s*$)/ig,""); } function trimAll(value){//去掉所有空格 return value.replace(/\s/ig,""); } function test(){ var val = trimAll(" 1 2 "); }