javascript清除字符串前后的空格(兼容所有浏览器器)
function trim(str) { if (str && typeof str === 'string') { return str.replace(/^\s+|\s+$/g,''); } } console.log(trim(' abcd efg '));
function trim(str) { if (str && typeof str === 'string') { return str.replace(/^\s+|\s+$/g,''); } } console.log(trim(' abcd efg '));