IE 11 AngularJS错误 - 对象不支持属性或方法'from'

not*_*nce 5 html javascript angularjs internet-explorer-11

在我的JavaScript中,我有一个通过HTML detectEnvironmentAndGetLEAndDepot()调用的函数onload.我正在使用wicket,需要获取后端保存的值,所以我将它们发送到屏幕,隐藏它们,然后<span>从我的JS 搜索值中的name值,if(v.getAttribute('name') === 'LE'){do stuff}或者if(v.getAttribute('name') === 'depot'){do stuff}(我肯定不会)最优雅的解决方案,但我需要一个快速的解决方案!).然后在函数中detectEnvironmentAndGetLEAndDepot()我做了一些格式化等,所以数据是可用的.

detectEnvironmentAndGetLEAndDepot() 功能(很长,只有相关部分) -

detectEnvironmentAndGetLEAndDepot = function() {

    Array.from(document.getElementsByTagName('span')).forEach(function(v) {

//Search name tag for particular names, then do formatting
}
Run Code Online (Sandbox Code Playgroud)

当我在IE11中打开它时,我在弹出窗口中得到错误,该弹出窗口SCRIPT438: Object doesn't support property or method 'from'与上面方法的第一行相关 - Array类.非常感谢.

Sta*_*ash 6

由于Array.fromIE不支持该方法,您可以尝试使用:

[].slice.call(document.getElementsByTagName('span')).forEach(function(v) {});
Run Code Online (Sandbox Code Playgroud)

这不需要使用任何第三方库.

  • 这似乎有效.但是我将代码更改回Array.from - 它也有效.我的应用程序似乎令人难以置信的气质(在IE中),有时它的工作有时它不会.最重要的是,一旦我打开开发者工具,一切都会中断......我甚至没有起始位置.我讨厌IE. (2认同)