我在我的通用 js 中创建了一个名为 startsWith 的扩展函数。
它是这样的:
String.prototype.startsWith = function (str) {
if (this.indexOf(str) == 0) {
return true;
}
return false;
}
在 IE9 中运行时,我收到一条错误消息:“对象不支持属性或方法‘indexOf’”。
在调试器中查看时,这似乎是 DispHTMLWindow2。
有什么帮助吗?
谢谢。
最佳答案
您可以尝试以下摘自 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]+$/, ""))}
关于javascript - IE9 this = DispHTMLWindow2 在原型(prototype)函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6691618/