on()jQuery'nin olay bağlama işlevlerinin çoğunu birleştirme girişimidir. Bu, livevs ile verimsizliklerin toplanması avantajına sahiptir delegate. JQuery'nin gelecekteki sürümlerinde, bu yöntemler kaldırılacak ve yalnızca onveone bırakılacaktır.
Örnekler:
// Using live()
$(".mySelector").live("click", fn);
// Equivalent `on` (there isn't an exact equivalent, but with good reason)
$(document).on("click", ".mySelector", fn);
// Using bind()
$(".mySelector").bind("click", fn);
// Equivalent `on`
$(".mySelector").on("click", fn);
// Using delegate()
$(document.body).delegate(".mySelector", "click", fn);
// Equivalent `on`
$(document.body).on("click", ".mySelector", fn);
Dahili olarak, jQuery tüm bu yöntemleri ve stenoi olay işleyicisi ayarlayıcılarını on()yönteme eşler ve bundan sonra bu yöntemleri göz ardı etmeniz ve yalnızca şunu kullanmanız gerektiğini belirtir on:
bind: function( types, data, fn ) {
return this.on( types, null, data, fn );
},
live: function( types, data, fn ) {
jQuery( this.context ).on( types, this.selector, data, fn );
return this;
},
delegate: function( selector, types, data, fn ) {
return this.on( types, selector, data, fn );
},
Bkz. Https://github.com/jquery/jquery/blob/1.7/src/event.js#L965 .