str爲要去除空格的字符串: 去除所有空格: str = str.replace(/\s+/g,""); 去除兩頭空格: str = str.replace(/^\s+|\s+$/g,""); 去除左空格: str=str.replace( /^\s*/, ''); 去除右空格: str=str.replace(/(\s*$)/g, "");
js去掉空格
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
str爲要去除空格的字符串: 去除所有空格: str = str.replace(/\s+/g,""); 去除兩頭空格: str = str.replace(/^\s+|\s+$/g,""); 去除左空格: str=str.replace( /^\s*/, ''); 去除右空格: str=str.replace(/(\s*$)/g, "");