jQuery: .select() and .focus() method difference

前端 未结 2 806
说谎
说谎 2021-02-07 07:07

In jQuery, what is basic difference between .select() & focus() and what are their appropriate using places?

相关标签:
2条回答
  • 2021-02-07 07:12

    They have their differences:

    • .select(): will fire when TEXT is selected.
      • Limitted to <input> and <textarea> elements.
    • .focus(): will fire when an element receives focus i.e. an input box is clicked on, tabbed into, etc.
      • Also limitted but to a wider range of elements, mostly form elements such as <input>, <select>, <a>
    0 讨论(0)
  • 2021-02-07 07:30

    From the jQuery documentation:

    select

    The select event is sent to an element when the user makes a text selection inside it. This event is limited to <input type="text">fields and <textarea> boxes.

    focus

    The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property.

    0 讨论(0)
提交回复
热议问题