简体   繁体   English

禁用并启用点击处理程序

[英]Disable and enable click handler

I have this code: 我有以下代码:

jQuery(".view-kems-tickets-calendar td.single-day").not(".no-entry, .empty").click(function() {
  jQuery(".all-day-items", this).slideDown("slow");
  jQuery(this).off("click");
});

jQuery(".view-kems-tickets-calendar .close-all-day").click(function() {
  jQuery(".all-day-items").slideUp("fast", function() {
  });
});

So what it does: It makes clickable td.single-day and displays the .all-day-items class element which exists inside of this td tag . 所以它的作用是:它使td.single-day成为可单击的,并显示此td标签内部存在的 .all-day-items类元素。 The .all-day-items element contains .close-all-day element which closes previously opened .all-day-items element. .all-day-items元素包含.close-all-day元素,该元素关闭先前打开的.all-day-items元素。 The problem is that while clicking at .close-all-day element at the same time I click in td.single-day so it closes and opens again. 问题在于,当我同时单击.close-all-day元素时,我单击了td.single-day,因此它关闭并再次打开。 I put this line: 我把这一行:

jQuery(this).off("click"); 

to disable it, but how do I activate it again in complete function? 禁用它,但是如何在完整功能中再次激活它? I tried couple of methods, but it always behave as before (it closes and opens again the .close-all-day element). 我尝试了几种方法,但是它始终像以前一样工作(它关闭并再次打开.close-all-day元素)。

This is how it doesn't work: :) the code: http://codepen.io/anon/pen/GgJZOp 这是不起作用的方式::)代码: http : //codepen.io/anon/pen/GgJZOp

Maybe this helps you: 也许这可以帮助您:

jQuery(".view-kems-tickets-calendar td.single-day").not(".no-entry, .empty").click(function(e){
    if(!$(e.target).is('.close-all-day')){
        jQuery(".all-day-items", this).slideDown("slow");
    }
});

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

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