javascript中去掉字符串前面的0

var str = "00012300325300"; 
str = str.replace(/\b(0+)/gi,"");    // 去掉字符串前面的0
document.write("str=" + str + "</br>");

上面代码中replace的正则表达式就是去掉字符串前面的0

 

var str = "sfsd sdf df  ";
str = str.replace(/\s*/g,"");   // 去掉空格

  上面的正则表达是即为去掉字符串中的空格

posted @ 2014-07-11 14:07  萍踪侠影B302  阅读(2090)  评论(0编辑  收藏  举报