问题描述:

This question already has an answer here:

  • JavaScript closure inside loops – simple practical example

    29 answers

网友答案:

try this:

document.getElementById(sel.id).addEventListener("change", function () {
        resetValues(this.id);
    });

by the time the event happens sel.id will be always 6. You need to address the element you added the listener to.

网友答案:

Try using resetValues(this.id); instead of resetValues(sel.id);

I think when you call resetValues(sel.id); here sel variable is sending reference to the function. And when you change value of sel it will change all value of previous sels

相关阅读:
Top