1 # str为要去除空格的字符串: 2 # 去除所有空格: 3 str = str.replace(/s+/g,""); 4 # 去除两头空格: 5 str = str.replace(/^s+|s+$/g,""); 6 # 去除左空格: 7 str = str.replace( /^s*/, ''); 8 # 去除右空格: 9 str = str.replace(/(s*$)/g, "");
网上搜集整理