Detect which form input has focus using JavaScript or jQuery

前端 未结 9 2541
灰色年华
灰色年华 2020-11-29 09:20

How do you detect which form input has focus using JavaScript or jQuery?

From within a function I want to be able to determine which form input has focus. I\'d like

9条回答
  •  [愿得一人]
    2020-11-29 09:40

    document.activeElement, it's been supported in IE for a long time and the latest versions of FF and chrome support it also. If nothing has focus, it returns the document.body object.

提交回复
热议问题