Var a=1
A=a + 1
The console. The log (a)
})
The output has been to 2
CodePudding user response:
Each click will reset the value of a, make a statement on the outside of the function is okCodePudding user response:
A declared as local variables, here will be a statement on the event, become a global variableCodePudding user response:
To add static var in front of a=1, a static variable, or for a global variable in function declarations outside can solve the problem of the currentJunction post rate 66.67%
A.a ddEventListener (' click ', function () {
The static var a=1
A=a + 1
The console. The log (a)
})
Or
Var a=1
A.a ddEventListener (' click ', function () {
A=a + 1
The console. The log (a)
})