我要做的是设置它,以便在单击链接时触发警报。是否可以定义首先触发哪个警报?
$("#container").delegate("a.link", "click", function(){
alert("This was message #1");
});
$("#container").delegate("a.link", "click", function(){
alert("This was message #2");
});
答案 0 :(得分:3)
我在代码中使用的一种方法是为第二个事件监听器设置第二个事件类型:
$("#container").delegate("a.link", "click", function(){
alert("This was message #1");
$(this).trigger("click-event-2");
});
$("#container").delegate("a.link", "click-event-2", function(){
alert("This was message #2");
});
$("#container").on("click","a.link", function(){
alert("This was message #1");
$(this).trigger("click-event-2");
});
$("#container").on("click-event-2","a.link", function(){
alert("This was message #2");
});