the code is as follows
$(function(){
$(".a").on("click",function(){
var counter=0
counterPP
})
$(".b").on("click",function(){
if(counter>=3){
alert(3)
}
})
})
there are two buttons, an and b, click a, and the variable counter will increase by 1. When the b button is clicked, a prompt box will pop up if the variable counter is greater than or equal to 3.
because counter is not a global variable, it will be destroyed after each click, so every time counter is 1, how to implement it if you use a closure. If the global variable is no longer used, how should the countervalue in the a button function be obtained in the function clicked by the b button?