<script type="text/javascript">
// 去除所有空格
String.prototype.trimAll = function()
{
return this.replace(/\040/g, "");
}
//去除左右两端的空格
String.prototype.trimLR = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去除左端的空格
String.prototype.trimL = function()
{
return this.replace(/(^\s*)/g, "");
}
//去除右端的空格
String.prototype.trimR = function()
{
return this.replace(/(\s*$)/g, "");
}
</script>
使用方法:比如有个JS里的变量叫data,调用的话就只要var newdata = data.trimAll()就可以去除data中所有空格了。