js 去掉空格
function String.prototype.Trim() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
function String.prototype.Ltrim() { return this.replace(/(^\s*)/g, ""); }
function String.prototype.Rtrim() { return this.replace(/(\s*$)/g, ""); }
var str = " hi! ";
var left = str.LTrim(); //结果:"hi! "
var right = str.RTrim(); //结果:" hi!"
var t = str.Trim(); //结果:"hi!"
或者:
var str = " h i ! ";
str = str.replace(/[ ]/g,""); //替换所有