I created an extension function called startsWith in my general js.
It goes like this:
String.prototype.startsW开发者_StackOverflowith = function (str) {
if (this.indexOf(str) == 0) {
return true;
}
return false;
}
When running in IE9 i get an error saying: "Object doesn't support property or method 'indexOf'".
When looking in the debugger it seems like this is DispHTMLWindow2.
Any help?
Thanks.
You could try the following as taken from this site
String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}
String.prototype.trim = function(){return
(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
精彩评论