2

我要做的是设置它,以便在单击链接时触发警报。是否可以定义首先触发哪个警报?

$("#container").delegate("a.link", "click", function(){                    
    alert("This was message #1");
});

$("#container").delegate("a.link", "click", function(){                    
    alert("This was message #2");
});
4

1 回答 1

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");
});

另外值得一提的是,delegate.on()

$("#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");
});
于 2013-04-07T05:22:27.647 回答