English, British feliratok

← 03-12 The_Convenience_Method

Beágyazókód kérése
18 Languages

Showing Revision 1 created 05/27/2020 by Tanisha Paryani.

  1. You have been setting up event
    listeners using jQuery's on method.
  2. Now this works really well, but
  3. jQuery also has some convenience
    methods that you can use.
  4. Let's take a look.
  5. This is how we would set
    up an event listener for
  6. a keypress on every input field.
  7. We could rewrite this using jQuery's
    convenience method by replacing the on
  8. with the keypress.
  9. And now we don't have
  10. to specify the event type, because the
    convenience method implies
  11. it. See?
  12. Much nicer. Looking
  13. at the keypress documentation,
  14. you'll see JQuery point out
    that the keypress function
  15. is actually a shortcut for
    the on method,
  16. passing keypress as an argument.
  17. It's important to know that there aren't
    convenience methods for every event type.
  18. Take a minute to look up what methods
    are available on jQuery's API site.
  19. I have linked to the appropriate
    page in the instructor notes.