Intercept click event on a button, ask for confirmation, then proceed

后端 未结 4 952
陌清茗
陌清茗 2020-12-08 10:33

Based on a variable SomeCondition, I need to intercept a click event on a button, and ask for confirmation, if they say ok, proceed, otherwise ignore click.

4条回答
  •  情话喂你
    2020-12-08 11:22

    To anyone who is looking for a simple solution (not particular to the special condition mentioned here)

    Just add this attribute to the button:

    .... , onclick = "return confirm('are you sure?')"
    

    When the confirmation box returns a false, the click event gets cancelled. Note: The onclick handler explicitly mentioned inline will override any other bindings.

提交回复
热议问题