i have this situation:

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

in IE8 i get Object doesn't support property or method 'indexOf'

i could probably use something like $.inArray("/bob/", image), but im not sure about lastIndexOf

any ideas how can i solve this?

有帮助吗?

解决方案

Try using a regex, something like

if(/\/(bob|ginger|grabs)\//.test(image) || /^[^\/]*\/$/.test(image)){
}

其他提示

If you want to solve it with jQuery, you could do

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

i.e. look for the next occurrence of / after the first occurrence. This assumes that / is always present in the array. If not, then the equivalent would be

var index =  $.inArray("/", image);
if (.... || (index === -1 ||  $.inArray("/", image, index) === -1)) {
   // ...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top