简体   繁体   English

简单的jQuery click事件问题

[英]Simple jQuery click event issue

I'm using a simple jQuery content panel switcher that I am trying to add a close button to. 我正在使用一个简单的jQuery内容面板切换器,试图将其添加一个关闭按钮。 The close button is working but then after using the close button I can't re-open a panel again. 关闭按钮可以正常工作,但是使用关闭按钮后,我无法再次打开面板。 The code for the panel switcher plugin is below: 面板切换器插件的代码如下:

jcps.fader = function(speed, target, panel) {
jcps.show(target, panel);
if (panel == null) {panel = ''};
$('.switcher' + panel).click(function() {
    var _contentId = '#' + $(this).attr('id') + '-content';
    var _content = $(_contentId).html();
    if (speed == 0) {
        $(target).html(_content);
    }
    else {  
        $(target).fadeToggle(speed, function(){$(this).html(_content);}).fadeToggle(speed);
    }
});
};

And here is the call in my HTML page that I have added the click event to: 这是我的HTML页面中将click事件添加到的调用:

    $(document).ready(function() {
       jcps.fader(300, '#switcher-panel');
         $(".close").live('click',function(){
         $(".content").fadeOut("slow");
         });
    });

This all works fine for closing the content panel but I am unable to open a panel again after clicking close. 所有这些对于关闭内容面板都可以正常工作,但是单击关闭后,我无法再次打开面板。

  • Create a variable outside the scope of both of these functions. 在这两个函数的范围之外创建一个变量。
  • Set it to false by default. 默认情况下将其设置为false。 Set it to true on close 关闭时将其设置为true
  • Create an If condition for true/false (inside your onClick code), and have it operate close/open code in each of these branches 为true / false(在onClick代码内)创建一个If条件,并在每个分支中让其操作关闭/打开代码

Does this apply/make sense? 这是否适用/有意义?

edit-- 编辑 -

 $(document).ready(function() {
   jcps.fader(300, '#switcher-panel');
     $(".close").live('click',function(){
     if (Clicked == true){
         //run jquery code to hide
     } else {
         //run jquery code to show
     }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM