Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带Internet Explorer 8的JavaScript_Javascript_Internet Explorer_Browser - Fatal编程技术网

带Internet Explorer 8的JavaScript

带Internet Explorer 8的JavaScript,javascript,internet-explorer,browser,Javascript,Internet Explorer,Browser,在上面的代码中,带有indexOf方法的if条件在IE8中无法正常工作,但在其他浏览器中可以正常工作 在IE8中,即使在字符串stringContent中找到toSearch中的内容,它也会进入循环中 我不确定问题是出在indexOf方法还是代码中的其他地方。让我知道解决这个问题的方法!谢谢 更新 我刚刚在调试IE时注意到,toSearch变量在mozilla和其他浏览器中显示为“\”D:\company\”而不是“D:\company” 有什么办法可以克服这个问题吗?正如你在这篇文章中看到的那

在上面的代码中,带有
indexOf
方法的if条件在IE8中无法正常工作,但在其他浏览器中可以正常工作

在IE8中,即使在字符串
stringContent
中找到
toSearch
中的内容,它也会进入循环中

我不确定问题是出在
indexOf
方法还是代码中的其他地方。让我知道解决这个问题的方法!谢谢

更新

我刚刚在调试IE时注意到,toSearch变量在mozilla和其他浏览器中显示为“\”D:\company\”而不是“D:\company”

有什么办法可以克服这个问题吗?

正如你在这篇文章中看到的那样,IE8中没有

您可以考虑正则表达式,也可以查看MDN的回退:


您能否尝试将var元素更改为其他名称,例如var elem,并查看它是否有效?a我现在尝试了。即使在那时,它也不起作用。我尝试将实现的索引粘贴到脚本的开头。但即使在那时它也不起作用。如何使用regex做到这一点?请参见:也添加了这个
regexIndexOf
。结果没有变化。我不能复制这个,因为我没有IE8。但如果使用得当,它应该会起作用(19张赞成票和一张接受票)
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;
}