简体   繁体   中英

jQuery .on() method with multiple events - passing argument to event handler function

Here is the code :

$('.el')
    .drag("init", function () {
        //
    })
    .drag("start", function () {
        //
    })
    .drag("end", function () {
        //
    });

I couldnt find a way to pass the parameters in the case below

$('.el').on({

   drag: function(){
       //*init* functions  
   },

   drag: function(){
       //*start* functions  
   },

   drag: function(){
       //*end* functions  
   }

})

Is it possible to pass parameters while using on event delegation for multiple events at once. Or the only solution is using on for multiple times.

You should probably lead with the fact that you're using a plugin, more specifically this plugin .

The docs are pretty clear, there are events built in, such as draginit , dragend etc. that can be used instead of the drag() method

$(document).on({

   draginit: function(){
       //*init* functions  
   },

   dragstart: function(){
       //*start* functions  
   },

   dragend: function(){
       //*end* functions  
   }

}, '.el');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM