Javascript 单击后的jquery打开和关闭功能

Javascript 单击后的jquery打开和关闭功能,javascript,jquery,function,bind,unbind,Javascript,Jquery,Function,Bind,Unbind,我在我的网站上使用了2个jquery代码 第一个代码是: function bottom_open() { $('.cartouche_bottom').css('position','absolute').animate({ top :$(".top_table").height() - 1, }); $('.bottom_close').show(); //$('.layout_bottom').

我在我的网站上使用了2个jquery代码

第一个代码是:

    function  bottom_open() {


        $('.cartouche_bottom').css('position','absolute').animate({
        top :$(".top_table").height() - 1,
        });

        $('.bottom_close').show();
        //$('.layout_bottom').stop().animate({height :0});

    }
第二个是:

    function  bottom_close() {



        $('.cartouche_bottom').css('position','fixed').animate({
        top : cartouche_bottom_position
    });
        $('.bottom_close').hide();
}
}

我试图做的是当第一个函数被执行时(通过单击函数),解除绑定该函数,然后当第二个函数被执行时,重新绑定第一个函数。我找不到做这件事的方法

以下是我尝试过的:

function bottom_cartouche(){

    var cartouche_bottom_position = $(window).height() - $('.top_table').height() - $('.layout_bottom').height();
/第一个操作,单击“.cartouche\u bottom\u inside”时,执行函数bottom\u open(),然后解除绑定bottom\u open()。 因此,如果我们再次单击“.cartouche\u bottom\u inside”bottom\u open()将不会执行

/然后,当单击“.bottom\u close”时,执行第二个函数bottom\u close()并重新绑定第一个函数bottom\u open()。 因此,如果我们再次单击“.cartouche\u bottom\u inside”,将执行bottom\u open()/

下面是一个解释:

第一个操作,单击“.cartouche\u bottom\u inside”时,执行函数bottom\u open(),然后解除绑定bottom\u open()。 因此,如果我们再次单击“.cartouche\u bottom\u inside”,将不会执行bottom\u open()

然后,当单击“.bottom\u close”时,执行第二个函数bottom\u close()并重新绑定第一个函数bottom\u open() 因此,如果我们再次单击“.cartouche\u bottom\u inside”,将执行bottom\u open()。。。等等

我不知道我做错了什么

有人能帮我吗


非常感谢您的时间和帮助,

您可能可以将函数绑定到某些类,然后根据需要将这些类添加到元素的适当位置并将其删除

编辑:另外,这里似乎有输入错误:

$('.bottom_close').click(function(){
    bottom_close();
    $('cartouche_bottom_inside').on('click');
});
应该是(注意选择器上缺少的“.”):


我只想添加和删除一个类,如下所示:

$('#buttonhere')。单击(函数(e){
if($(this).hasClass('firstPart')){
//做一部分。
底部_打开();
$(this.toggleClass('firstPart');
}
否则{
底部关闭();
$(this.toggleClass('firstPart');
}
})
试试这个

$('.bottom_close').click(function(){
  bottom_close();
  $('.cartouche_bottom_inside').on('click', function() {bottom_open() });
});

此行
$('cartouche\u bottom\u inside')。在('click')
不会做任何事情。正如@Mathletics指出的,.on('click')是一个方法,而不是一个事件。首先,你没有一个“.”。其次,如果要模拟单击,应使用
$('.carttouche\u bottom\u inside')。单击()。
$('.bottom_close').click(function(){
    bottom_close();
    $('cartouche_bottom_inside').on('click');
});
$('.bottom_close').click(function(){
    bottom_close();
    $('.cartouche_bottom_inside').on('click');
});
$('.bottom_close').click(function(){
  bottom_close();
  $('.cartouche_bottom_inside').on('click', function() {bottom_open() });
});