【发布时间】:2019-02-12 17:16:28
【问题描述】:
我只想将事件绑定到 jQuery 中的“页面”。
问题是代码不仅针对“页面”执行,而且在使用addClass 时针对所有后代执行。我只想在addClass 用于“页面”div 时触发事件。我该怎么做?
//https://stackoverflow.com/a/31859060/2947462
(function( func ) {
$.fn.addClass = function() { // replace the existing function on $.fn
func.apply( this, arguments ); // invoke the original function
this.trigger('eventAddClass'); // trigger the custom event
return this; // retain jQuery chainability
}
})($.fn.addClass); // pass the original function as an argument
$(document).on( "eventAddClass", 'div[data-role="page"]', function(event) {
//code - do some stuff
});
【问题讨论】:
标签: jquery jquery-mobile jquery-selectors