Run javascript function only once

后端 未结 3 1985
不知归路
不知归路 2020-12-10 21:48

I have this simple javascript function:



        
3条回答
  •  天涯浪人
    2020-12-10 21:56

    Write the code as follows:

    
    

    Once your click listener is set, your previous if statement's location wasn't executed anymore. Only the code inside the on click function.

    Alternatively, you can unbind the onClick listener instead of setting popup = '1'. Try the following:

    
    

    Much cleaner, and as Mathletics has mentioned, cleans unnecessary callbacks from memory.

提交回复
热议问题