标签:remove str space alert return pac rem 去除 字符串
去除字符串前后的空格
function trim(str) {
return str.replace(/(^\s+)|(\s+$)/g, "");
}
去除字符串中所有空格
function removeAllSpace(str) {
return str.replace(/\s+/g, "");
}
用法举例:
alert(trim(‘ ab cd ‘)); //结果: ab cd
alert(removeAllSpace(‘ ab cd ‘)); //结果: abcd
标签:remove str space alert return pac rem 去除 字符串
原文地址:http://www.cnblogs.com/yangxiong/p/7121223.html