我有一个与此非常相似的问题:重新绑定,但我不明白解决方案。
我有一个用于左右滑动 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.
};
});
});