2010-07-21 50 views

回答

3

你可以把所有的事件放在一個數組中,併爲每個元素添加你的函數。

例:

events=[ $("#test1").click, $("#test1").hover ]; 

for (e in events) { 
    e(some_function); 
}; 
4

這似乎凌亂。我相信這應該起作用。

$('#test1').bind('click mouseenter mouseleave', some_function); 

記住.hover()有兩個函數作爲參數,所以只有一個功能可能會產生意想不到的效果。

+1

我想補充一點,你可以使用'event.type'(http://api.jquery.com/event.type/)找出哪個事件被觸發。 – Mottie 2010-07-21 21:28:31

相關問題