//去除左右空格,包括全角半角 function trim(str){ return str.replace(/^( |[\s ])+|( |[\s ])+$/g, ""); } 转自:http://www.phpzixue.cn/detail650.shtml