js字符串去掉所有空格

字符串去掉所有空格

"abc 123 def".replace(/\s/g, "")

 字符串去掉左右两端空格

" abc 123 def ".replace(/(^\s*)|(\s*$)/g, "");

字符串去掉左边空格

" abc 123 def ".replace(/(^\s*)/g,"");

字符串去掉右边空格

" abc 123 def ".replace(/(\s*$)/g,"");

 

posted @ 2017-10-23 11:09  成忠  阅读(333)  评论(0编辑  收藏  举报