在我的 JavaScript 中,我有一个函数 detectEnvironmentAndGetLEAndDepot()
onload
。我正在使用检票口,需要获取后端保存的值,所以我将它们触发到屏幕上,隐藏它们,然后从我的 JS 中搜索 <span>
值 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
}
当我在 IE11 中打开它时,我在弹出窗口中收到错误 SCRIPT438: Object doesn't support property or method 'from'
与上述方法的第一行相关 - Array
类。非常感谢帮助。
原文由 notAChance 发布,翻译遵循 CC BY-SA 4.0 许可协议
由于IE不支持
Array.from
方法,你可以尝试使用:这不需要使用任何第 3 方库。