简体   繁体   English

在特定的点击事件之后触发点击事件。(绑定功能)

[英]Triggering Click Event after a particular click event.(Bind-function)

Below is my html and jquery. 下面是我的html和jquery。 Thorugh jquery i am adding and remove class-disBloS to the div named inn by toggleClass funciton when logBtn is clicked. 当我单击logBtn时,我要通过toggleClass函数将class-disBloS添加和删除到名为inn的div中。
Also i made a funciton to remove the disBloS form the Div(inn) when the user clicks any were on the page. 我也做了一个功能,当用户单击页面上的任何内容时,从Div(inn)删除disBloS。 but the problem is that function triggers every time when i click any were in the body. 但是问题是,每次我单击体内的任何东西时,函数都会触发。 My need is It has to trigger only when the logBtn Button is clicked before that. 我需要的是,只有在此之前单击logBtn按钮时才必须触发。 it dosent has to trigger when the logBtn Button is not clicked Before 当未单击logBtn按钮时,它必须触发

Html Code HTML代码

<a href="#" class="togg" id="logBtn"></a>
<div class="inn"></div>

Jquery to add disBloS when clicked logBtn jQuery在单击logBtn时添加disBloS

$('#logBtn').click(function() {
    arrNext = $(this).next();
    arrow = $(this);
    $(this).next().toggleClass('disBloS');
    $(this).toggleClass('up');
});

Jquery to remove disBloS when clicked any were on page jQuery在单击页面上的任何页面时删除disBloS

$('body').click(function(e){
  if(e.target.id !== 'logBtn') {
          $(arrNext).removeClass('disBloS');
          $(arrow).removeClass('up');

  }

}); });

Does this solve your problem ? 这能解决您的问题吗? This will stop the click on logBtn from propagating to the body. 这将阻止单击logBtn传播到主体。

$('#logBtn').click(function(e){
    $(this).next().toggleClass('disBloS');
    e.stopPropagation();
});

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

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