<Div>
<Input id = "one" type = "button" value = "button 1"/>
<Input id = "two" type = "button" value = "button 2"/>
<Input id = "three" type = "button" value = "button 3"/>
<Button onclick = location. Reload ()> Reset </button>
</Div>
<SCRIPT>
Function click_times (){
For (VAR I = 1; I ++ ){
Return function (){
Alert (I ++)
}
}
}
VaR temp = [];
VaR node = Document. getelementsbytagname ('input ');
For (VAR q = 0; q <node. length; q ++ ){
Temp. Push (click_times ());
Node [Q]. addeventlistener ('click', temp [Q])
}
</SCRIPT>
I haven't posted any blog posts yet, but I don't know what the effect is. This code is not complicated. People who know the closure can understand it all. The goal is to click the button and the numbers in the pop-up box will increase one by one, the difference is that the three buttons do not affect each other. I put the method in the array to be traversed.
Example of using closures