why does alert() break code execution?

后端 未结 4 902
北荒
北荒 2020-12-11 02:38

When we use alert(), some times the code breaks.

For example:

HTML:

Hi

Javascript:

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 02:49

    Because you are catching the first click and showing an alert. The second click doesn't get caught because the alert now has the focus.

    If you log to the console, then both clicks get caught and you will notice that "a" gets logged twice.

提交回复
热议问题