点击事件不起作用 [英] on click event not working
问题描述
我有一个将有多个子组件的组件,首先,如果我单击任何组件,则应触发相应的click事件,此后该div中的任何其他组件click事件都不应触发,除非使用鼠标移出边界线并再次返回.
I have one in which I will be having multiple child components, at first if I click at any component, the corresponding click event should be triggered and after that no other component click event within that div should not trigger unless otherwise the mouse moves out of the borderline and again comes back in.
我已经完成了以下工作,现在第一部分已经完成,即当我们单击任何组件时,将触发相应的click事件,此后,自从正在使用.off("click");
I have done the following stuff to achieve this, right now the first part is complete that is when we click at any component the corresponding click event will be triggered and after that no other component click event within that div will occur since I am removing the click event using .off("click");
但是现在的问题是,当鼠标离开div时,我想重新附加单击事件,而在使用以下代码时却没有发生
but now the issue is that when the mouse leaves the div, I want to reattach the click event which is not happening when i used the following code,
$('.parent *').on('mouseleave', function () {
$(".parent *").on('click')
});
任何人都可以告诉我一些解决方法
Can anyone please tell me some solution for this
JSFiddle
推荐答案
$(document).ready(function () {
function clickEvents(){
$("#myButton").off().on('click',function () {
console.log('myButton clicked....');
});
$("#myHyperLink").off().on('click',function () {
console.log('myHyperLink clicked....');
});
}
$('.parent').on('mouseleave', function () {
clickEvents()
});
$(".parent").click(function (event) {
$(".parent *").off("click");
});
clickEvents()
});
您也可以尝试这个.
这篇关于点击事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!