JavaScript FocusOut - get the element that receives focus

后端 未结 4 796
青春惊慌失措
青春惊慌失措 2021-02-13 13:03

When the FocusOut event is raised, how do you know which element receives the focus?

The correct way seems to be to use the event\'s relatedTarget p

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 13:06

    I believe what you're looking for is document.activeElement.

    Returns the currently focused element, that is, the element that will get keystroke events if the user types any. This attribute is read only.

    https://developer.mozilla.org/en-US/docs/Web/API/document.activeElement

提交回复
热议问题