1
我有一個問題非常類似於這個:Rebind但我不明白的解決方案。重新綁定單擊事件
我有一個左右滑動html內容的旋轉木馬...用於滑動內容的左右圖像。如果到達轉盤末端,則右側滑動圖像上的單擊事件應解除綁定。如果點擊左側圖像,右側圖像的點擊事件應該再次被限制......像下面這樣重新綁定似乎不起作用。看起來我應該存儲一個對點擊事件的引用,但我無法做到。
$(document).ready(function() {
//when user clicks the image for sliding right
$('#right_scroll img').click(function(){
// code for sliding content to the right, unless end is reached
if($('#carousel_ul li:first').attr('id') == fifth_lli){ // end carousel is reached
$('#right_scroll img').removeAttr('onmouseover');
$('#right_scroll img').removeAttr('onmouseout');
$('#right_scroll img').removeAttr('onmousedown');
$('#right_scroll img').unbind('click');
$('#right_scroll img').attr("src", "Images/gray_next_1.png");
};
});
//when user clicks the image for sliding left
$('#left_scroll img').click(function(){
//if at end of carousel and sliding back to left, enable click event for sliding on the right...
if($('#carousel_ul li:first').attr('id') == fifth_lli){
$('#right_scroll img').attr("src", "Images/red_next_1.png");
$('#right_scroll img').bind('click'); // this doesn't work.
};
});
});
與其纏繞綁定/解除綁定事件,爲什麼不簡單地檢查輪播是否結束,然後什麼都不做。 –
可能是因爲他在內聯處理程序中定義了它們。 –