最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery.on callback parameters - Stack Overflow

programmeradmin1浏览0评论

In the documentation for .on(), the parameters are given as follows:

.on( events [, selector ] [, data ], handler )

With regards to the handler parameter (i.e. the callback function):

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.

When are any extraParameter arguments passed to the callback function? There are a lot of aliases for .on() but I haven't e across any that pass more than the eventObject parameter.

In the documentation for .on(), the parameters are given as follows:

.on( events [, selector ] [, data ], handler )

With regards to the handler parameter (i.e. the callback function):

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.

When are any extraParameter arguments passed to the callback function? There are a lot of aliases for .on() but I haven't e across any that pass more than the eventObject parameter.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jun 17, 2015 at 5:50 rink.attendant.6rink.attendant.6 46.5k64 gold badges110 silver badges157 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

There is an example in the documentation:

$( "div" ).on( "click", function( event, person ) {
  alert( "Hello, " + person.name );
});

//You can trigger an event without user action
$( "div" ).trigger( "click", { name: "Jim" } );

When are any extraParameter arguments passed to the callback function?

Utilizing .trigger(eventType [,extraParameters])

var obj = $({})

obj.on("evt", function(e, a, b) {
  console.log(e, a * b)
});


obj.trigger("evt", [Math.random(), 100])
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>

发布评论

评论列表(0)

  1. 暂无评论