function trim(str) { if (str && typeof str === “string”) { return str.replace(/^\s+/,””).replace(/\s+$/,””); //去除前后空白符 } } console.log(‘—‘+trim(‘ jjj jjj ‘)+‘—-‘); // console.log(‘—‘+trim(‘ jjj jjj ‘)+‘—-‘);
function trim(str) { if (str && typeof str === “string”) { return str.replace(/^\s+/,””).replace(/\s+$/,””); //去除前后空白符 } } console.log(‘—‘+trim(‘ jjj jjj ‘)+‘—-‘); // console.log(‘—‘+trim(‘ jjj jjj ‘)+‘—-‘);