IE上的startsWith和endWith方法 2016-11-23 前端 f**k ie, javascript IE居然不支持这两个方法,好辣鸡!依赖包:Javascript浏览器相关方法 12345678910111213141516171819202122// 扩展IE浏览器的String原型方法var Iflat = Iflat || {};Iflat.Browser = { extend: { ieStringExtend: function () { var browser = Iflat.Browser.info(); if (browser.name === 'ie') { if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (prefix) { return this.slice(0, prefix.length) === prefix; }; } if (typeof String.prototype.endsWith != 'function') { String.prototype.endsWith = function (suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; }; } } return browser; } }} 上一篇 IE扩展Function.prototype.bind()方法 下一篇 IE上的new Date()