js实现endwith方法 <script> String.prototype.endWith = function (endStr) { var d = this.length - endStr.length; return (d >= 0 && this.lastIndexOf(endStr) == d) } // 调用 var test = 'test.html'; console.log(test.endwith('.html')) </script>