王奕茗js判断一个字符串是以某个字符串开头 2020/11/25 次浏览 console.log("123".startsWith("12")); //true console.log("123".endsWith("23"));//true // 兼容 if (typeof String.prototype.startsWith !=function) { String.prototype.startsWith =function (prefix){ return this.slice(0, prefix.length)=== prefix; }; }