Javascript 为什么我会有这个错误:对象不';t支持属性或方法';forEach&x27;对于Internet Explorer?
我正在使用maven开发jenkins插件上的Javascript,代码如下:Javascript 为什么我会有这个错误:对象不';t支持属性或方法';forEach&x27;对于Internet Explorer?,javascript,internet-explorer,internet-explorer-10,Javascript,Internet Explorer,Internet Explorer 10,我正在使用maven开发jenkins插件上的Javascript,代码如下: function arrayElements(element, index, array) { var arrayPaths = element.split("\\"); var projectSource = arrayPaths[2]; var array = element.split("_"); if (projectS
function arrayElements(element, index, array)
{
var arrayPaths = element.split("\\");
var projectSource = arrayPaths[2];
var array = element.split("_");
if (projectSource === global ) {
if (array[2]===filtro){
document.getElementById("source").options.add(new Option(arrayPaths[3], element));
}
}
}
function fillCompiledSource(object, projects)
{
document.getElementById("source").innerHTML = "";
global = document.getElementById("branches").value;
projects.forEach(arrayElements)
}
var projects = new Array();</script><script>
function fillCombo()
{
document.getElementById("source").innerHTML = "";
global = document.getElementById("branches").value;
var array = document.getElementById("branches").value.split('/');
global = array[1];
projects.forEach(arrayElements)
}
函数数组元素(元素、索引、数组)
{
var arrayPaths=element.split(“\\”);
var projectSource=arrayPaths[2];
var数组=元素分割(“”);
如果(projectSource==全局){
if(数组[2]==filtro){
document.getElementById(“source”).options.add(新选项(arrayPath[3],element));
}
}
}
函数fillCompiledSource(对象、项目)
{
document.getElementById(“源”).innerHTML=“”;
全局=document.getElementById(“分支”).value;
项目。forEach(阵列元素)
}
var projects=newarray();
函数fillCombo()
{
document.getElementById(“源”).innerHTML=“”;
全局=document.getElementById(“分支”).value;
var数组=document.getElementById(“分支”).value.split('/');
全局=数组[1];
项目。forEach(阵列元素)
}
只有在internet explorer中,只有当文档模式为IE8标准时,才会出现这种情况。我不知道原因是什么,也不知道如何解决
Pd:InternetExplorer是10Yeap,这是因为IE8没有实现数组.forEach(也没有很多其他更现代的JS方法)。如果你需要在IE8中工作,你必须(参见兼容性部分)
顺便说一句,MDN也为大多数其他不受支持的方法提供了资源。这可能会有所帮助。
要解决jQuery中的问题,请执行以下操作:
//This will fail in IE8
myObject.each(function(index, value){
//your code goes here
});
//This will work in IE8 and all modern browsers
$.each(myObject, function(index, value){
//your code goes here
});
您还可以将不存在的forEach函数绑定到Array.prototype.forEach
(function () {
if ( typeof NodeList.prototype.forEach === "function" ) return false;
NodeList.prototype.forEach = Array.prototype.forEach;
})();
我在这篇文章中发现它/IE8不支持
forEach
多次询问和回答我的问题是不同的,因为我不能使用JQuery,我正在使用maven开发Jenkins插件..@Daniel,谢谢。