我已经使用 indexOf 来检查我是否有特定的文本出现在句子中,如下所示
var temp = "";
temp="data not available";
if(temp.indexOf("datas") == 0){
alert("True");
}
else{
alert("false");
}
我遇到的问题是 indexOf 在 Internet Explorer 8 中不受支持。如何在IE8中也执行此操作? jquery 中是否有可用的默认替代函数?
我试过 inArray 但它只支持数组。
最佳答案
我认为您对支持哪些 indexOf()
感到困惑。
您正在使用 String.prototype.indexOf()
, 根据 Microsoft's documentation 从 IE6 开始支持.
是Array.prototype.indexOf()
仅从 IE9 开始支持。
关于javascript - IE8 中 indexOf for string 的备用函数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21772308/