Joke Collection Website - Cold jokes - How to solve the bug that clicking the button once and then pressing enter in js will also trigger the button event?

How to solve the bug that clicking the button once and then pressing enter in js will also trigger the button event?

The reason why pressing Enter will be created again is because when you click the button, you also get the focus on the button, if you just want to press Enter uneasily. Then use the blur () event to lose focus, or put focus () on another button.

If you only want to execute it once, you can add a public variable as a lock. When the variable is true, the function can be executed. Set the variable to false when the function is executed once. So it won't be executed twice.

var? mylock=? ture

Function? myclickfun(){

if(my lock = = true){

My Locke? =? Fake;

//Write the code needed to create the div here.

}

}