jquery on

https://api.jquery.com/on/

.on( events [, selector ] [, data ], handler )Returns: jQuery

Description: Attach an event handler function for one or more events to the selected elements.

  • version added: 1.7.on( events [, selector ] [, data ], handler )

    • events
      Type: String
      One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin".
    • selector
      Type: String
      A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element.
    • data
      Type: Anything
      Data to be passed to the handler in event.data when an event is triggered.
    • handler
      Type: Function( Event eventObject [, Anything extraParameter ] [, ... ] )
      A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false.
  • version added: 1.7.on( events [, selector ] [, data ] )

    • events
      An object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s).
    • selector
      Type: String
      A selector string to filter the descendants of the selected elements that will call the handler. If the selector is null or omitted, the handler is always called when it reaches the selected element.
    • data
      Type: Anything
      Data to be passed to the handler in event.data when an event occurs.

The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers. For help in converting from older jQuery event methods, see .bind(), .delegate(), and .live(). To remove events bound with .on(), see .off(). To attach an event that runs only once and then removes itself, see .one()

原文地址:https://www.cnblogs.com/chucklu/p/11102329.html