2010-03-07 75 views

回答

1

使用prevnext在當前/之後找到元素並激活它。您將需要從onclick事件中分離元素激活碼。

你使用

$(...).click(function() { 
    code 
    that 
    activates 
    "this" 
}); 

但現在你需要重複使用的激活碼,所以它脫鉤

activate = function(elem) { 
    code 
    that 
    activates 
    "elem" 
} 

$(img).click(function() { 
    activate(this) 
}); 

$(#left).click(function() { 
    activate(currentElement.prev()) 
}); 

$(#right).click(function() { 
    activate(currentElement.next()) 
}); 
+0

+1:謝謝,我很alredy使用,但有一些問題。好吧,你是什麼意思解耦元素激活碼? – Sarfraz 2010-03-07 17:06:07