//删除首尾空格 var pattern = /^s+/; //强制首 var str = ' goo gle '; var result = str.replace(pattern, ''); pattern = /s+$/; //强制尾 result = result.replace(pattern, ''); alert('|' + result + '|');
类似于$.trim(str)方法
//删除首尾空格 var pattern = /^s+/; //强制首 var str = ' goo gle '; var result = str.replace(pattern, ''); pattern = /s+$/; //强制尾 result = result.replace(pattern, ''); alert('|' + result + '|');
类似于$.trim(str)方法