js去除字符串空格

str.replace(/\s+/g,"");
str.replace(/\s|\xA0/g,"");

 

empName=empName.replace(/^\s+/g,"");       //去左
empName=empName.replace(/\s+$/g,"")        //去右
empName=empName.replace(/(^\s*)|(\s*$)/g, ""); //去左右

 

//去除空格 
String.prototype.Trim = function() { 
    return this.replace(/\s+/g, ""); 
} 
     
//去除换行 
function ClearBr(key) { 
    key = key.replace(/<\/?.+?>/g,""); 
    key = key.replace(/[\r\n]/g, ""); 
    return key; 
} 
     
//去除左侧空格 
function LTrim(str) { 
    return str.replace(/^\s*/g,""); 
} 
     
//去右空格 
function RTrim(str) { 
    return str.replace(/\s*$/g,""); 
} 
     
//去掉字符串两端的空格 
function trim(str) { 
    return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 
     
//去除字符串中间空格 
function CTim(str) { 
    return str.replace(/\s/g,''); 
}  

 

posted @ 2015-03-09 11:06  林锅  阅读(293)  评论(0编辑  收藏  举报