startsWith函数,时Java中的 在js使用时他并不是每个浏览器都有的,所以我们一般要重写一下这个函数
采用正则表达式实现startWith、endWith效果函数
String.prototype.startWith=function(str){var
reg=new
RegExp("^"+str);return
reg.test(this);}//测试ok,直接使用str.endWith("abc")方式调用即可String.prototype.endWith=function(str){var
reg=new
RegExp(str+"$");return
reg.test(this);}
还有对应的是endWith()
355




被折叠的 条评论
为什么被折叠?



