1、字符串去掉前后空格。 String.prototype.trim=function() { return this.replace(/(^\s*)|(\s*$)/g,''); } 2、IE浏览器不支持startsWith()和endsWith()方法,可改为正则表达式判断: n$ 匹配任何结尾为 n 的字符串。 ^n 匹配任何开头为 n 的字符串。