내 솔루션 (http://jsfiddle.net/968jj/1345/) :
$.fn.lastHandler = function (events, handler) {
var element = $(this);
events = events.split(' ');
for (var evt in events) {
var event = $(element).data("events")[events[evt]];
var hsucess = null;
$.each(event, function (i, h) {
if (h.handler == handler) {
hsucess = h;
}
});
var index = event.indexOf(hsucess);
if (index > -1) {
event.splice(index, 1);
event.push(hsucess);
}
}
}
사용 : 일부 HTML
< DIV ID와
$(function() {
var m1 = function(){ alert("mouseover to be the last"); };
var m2 = function(){ alert("mouseover to be the first"); };
var m3 = function(){ alert("mouseover to be the second"); };
$("#el").mouseover(m1);
$("#el").mouseover(m2);
$("#el").mouseover(m3);
$("#el").lastHandler('mouseover',m1);
});
= "엘자 "> </DIV >
일부 CSS
DIV {폭 : 200 픽셀; 높이 : 200px; 배경색 : 빨강; }
당신은 어떤 하나 또는 두 개 이상의 이벤트와 함께 사용할 수 있습니다 :
이
$("#el").lastHandler('keypress keyup change',fnHandler);
$("#el").lastHandler('click mouseover',fnHandler);
당신이 코드의 조각을 줄 수 있습니까? – dzida
비슷한 [질문] (http://stackoverflow.com/questions/2360655/jquery-event-handlers-always-execute-in-order-they-were-bound-any-way-around-th/2641047# 2641047). – Anurag
[이 질문에 대한 다른 해결책을 게시했습니다 (http://stackoverflow.com/a/19674508/315024). – Walf