English feliratok

← The Convenience Method

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

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  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 to specify
    the event type because the convenience
  10. method implies it.
  11. See?
  12. Much nicer.
  13. Looking at the keypress documentation,
    you'll see jQuery point out
  14. that the keypress function
    is actually a shortcut for
  15. the on method,
    passing keypress as an argument.
  16. It's important to know that there
    aren't convenience methods for
  17. 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.