jQuery supports the way dynamic parameters bind functions to events

  • 2020-05-16 06:24:52
  • OfStack

This article demonstrates how jQuery supports dynamic parameters for binding functions to events. Share with you for your reference. The specific analysis is as follows:

The js code below provides two methods for binding functions to events, of which method 2 is very useful for passing dynamic parameters


// methods 1
$('#foo').click(function(event) {
  alert('User clicked on "foo."');
}); 
 
// methods 2,  Support dynamic parameter transfer 
$('#foo').bind('click', {test1:"abc", test2:"123"}, function(event) {
  alert('User clicked on "foo."' + event.data.test1 + event.data.test2);
});

I hope this article is helpful for you to design jQuery program.


Related articles: