javascript - 转换 foreach 循环以与 Internet Explorer 兼容
问题描述
每个循环我都有以下内容:
function trackMeasurementChanged() {
var weightInputs = document.querySelectorAll('[id*="HeightAndWeight_Weight"]');
weightInputs.forEach(function(input) {
input.addEventListener('input', function(input) {
changedMeasurements.push("weight");
})
});
}
Internet Explorer 不支持此功能,并且未通过某些单元测试,因此我尝试将语法转换为以下内容:
for (var i = 0, len = weightInputs.Length; i < len; i++) {
var input = weightInputs[i];
console.log(input);
input.addEventListener('input', function (input) {
changedMeasurements.push("weight");
})
}
^ 至少这是我的尝试,但现在代码不起作用。没有错误,只是不再将“重量”字符串推入数组。请谁能指出我哪里出错了?我不熟悉旧语法。
解决方案
推荐阅读
- reactjs - 你如何处理加载时 Typescript 类型的局部状态变量?
- html - 私人聊天气泡相互叠加
- laravel - Lavavel js脚本
- java - 我的这个代码应该返回最常见元素的频率
- python - 使用python将简单矩阵转换为关联矩阵
- swift - Xcode 中 SwiftUI 中的分段 11 非零退出代码错误
- xml - 如何解决此项目构建错误:不可解析的 POM 错误?
- javascript - 很难处理由“导入”引起的错误
- django - localhost:8000 和 http://127.0.0.1:8000 有什么区别?
- javascript - 如何将一个数字映射到 1,这样 number/2 === 0.5 等等?