简体   繁体   English

带有 Internet Explorer 8 的 JavaScript

[英]JavaScript with Internet Explorer 8

var id = data.rslt;
var element = id.attr("crawlLocation");
if (element.indexOf("\\") != -1){
var toSearch = element.substring(0,element.lastIndexOf("\\"));
toSearch = "\"" + toSearch + "\"";
}
var stringContent = getInnerHTML('selectedCustodiansForIngestDiv');
if(stringContent.indexOf(toSearch) == -1){
  //This loop works fine on Firefox but not in IE8
}

function getInnerHTML(elmtId) {
var innerHTML = "";
if ($gElem(elmtId) != null) {
    innerHTML = document.getElementById(elmtId).innerHTML;
}
return innerHTML;
}

In the above code, the if condition with the indexOf method is not working as expected with IE8, but works fine with other browsers.在上面的代码中,带有indexOf方法的 if 条件在 IE8 上没有按预期工作,但在其他浏览器上工作正常。

In IE8, even if the content in toSearch is found in the string stringContent , it goes inside the loop.在 IE8 中,即使在字符串stringContent找到toSearch的内容,它stringContent进入循环。

I am not sure whether the problem is with indexOf method or somewhere else in my code.我不确定问题是出在indexOf方法上还是出在我代码中的其他地方。 Let me know a way to fix this!让我知道解决这个问题的方法! Thanks!谢谢!

UPDATE更新

I just noticed on debugging that in IE, the toSearch variable is appearing as "\\"D:\\company\\"" instead of "D:\\company"(In mozilla and other browsers).我刚刚注意到在 IE 中调试时,toSearch 变量显示为 "\\"D:\\company\\"" 而不是 "D:\\company"(在 mozilla 和其他浏览器中)。

Any idea to overcome this?有什么想法可以克服这个问题吗?

As you can see on this compatibility table it's not available in IE8.正如您在此兼容性表中看到的那样,它在 IE8 中不可用。

You can take a RegEx to account or see the fallbacks from MDN for:您可以考虑使用 RegEx 或查看 MDN 的回退:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM