Jquery 重新绑定单击事件

Jquery 重新绑定单击事件,jquery,bind,unbind,Jquery,Bind,Unbind,我有一个和这个问题非常相似的问题:但我不明白答案 我有一个旋转木马用于左右滑动html内容。。。具有用于滑动内容的左右图像。如果到达转盘末端,则右侧滑动图像上的单击事件应解除绑定。如果单击左图像,右图像的单击事件应再次绑定。。。像下面这样重新绑定它似乎不起作用。似乎我应该存储对单击事件的引用,但我无法正确获取它 $(document).ready(function() { //when user clicks the image for sliding right

我有一个和这个问题非常相似的问题:但我不明白答案

我有一个旋转木马用于左右滑动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.

            };      
        });  

  }); 

在移动转盘之前,只需检查转盘是否位于末端或起点,而不是解除和重新绑定

$(document).ready(function() {
    $('#right_scroll img').click(function() {
        if ($('#carousel_ul li:first').attr('id') !== fifth_lli) {
            //slide carousel right
        }
    });
    $('#left_scroll img').click(function() {
        if ($('#carousel_ul li:first').attr('id') !== first_lli) { //changed it to first first_lli, i figure that would be the end of the left scrolling
            //slide carousel left
        }
    });
});

与其乱搞绑定/解除绑定事件,不如简单地检查旋转木马是否在末尾,然后什么也不做。可能是因为他在内联处理程序中定义了它们。