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.
};
});
});
与其缠绕绑定/解除绑定事件,为什么不简单地检查轮播是否结束,然后什么都不做。 –
可能是因为他在内联处理程序中定义了它们。 –