1

我有这种情况:

if (image.indexOf("/bob/") != -1 || image.indexOf("/grabs/") != -1 || image.indexOf("/") == image.lastIndexOf("/")) {
    alert('success');
}

在 IE8 中我得到Object doesn't support property or method 'indexOf'

我可能会使用类似的东西$.inArray("/bob/", image),但我不确定lastIndexOf

任何想法我该如何解决这个问题?

4

2 回答 2

1

尝试使用正则表达式,例如

if(/\/(bob|ginger|grabs)\//.test(image) || /^[^\/]*\/$/.test(image)){
}
于 2013-10-23T03:11:50.583 回答
0

如果你想用 jQuery 解决它,你可以这样做

$.inArray("/", image, $.inArray("/", image)) === -1

即在第一次出现之后寻找下/一次出现。这假设它/始终存在于数组中。如果不是,那么等价的将是

var index =  $.inArray("/", image);
if (.... || (index === -1 ||  $.inArray("/", image, index) === -1)) {
   // ...
}
于 2013-10-23T03:12:25.973 回答