You can store the previous value of each input in the closure and add the delta to the total sum each time it changes.
const opSelect = document.querySelectorAll('.op .qltbox');
let sum = 0;
opSelect.forEach(opSelect => {
const a = opSelect.querySelector('input[type=text]');
let prev = 0;
a.onchange = function() {
let curr = +a.value;
sum += curr - prev;
prev = curr;
console.log('total sum:', sum);
};
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…