Why does a `click` event get triggered on my <button> when I press Enter on it?

前端 未结 4 794
梦毁少年i
梦毁少年i 2021-01-04 06:39

I\'m only adding a click event handler on my

4条回答
  •  爱一瞬间的悲伤
    2021-01-04 07:04

    Because for keyboard users (where a mouse is not available), when a button is in focus and you press Enter (possibly Space as well) it simulates a click event.

    This is the browser's accessibility support which most, if not all, browsers provide.

提交回复
热议问题