jQuery点击除div之外的所有东西,它是孩子们 [英] jQuery on click on everything but a div and it's children
本文介绍了jQuery点击除div之外的所有东西,它是孩子们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击任何地方时,我想做点什么,除非我点击一个div而它是孩子。这是我到目前为止所尝试的,但它不起作用(点击它的孩子仍然执行括号内的内容。
I want to do something when I click anywhere, except when I click a div and it's children. This is what I've tried so far, but it's not working (clicking on it's children still executes what is within the brackets.
$('body').on('click', '* :not(#calculator)', function(e){
我不能使用这样的东西:
I cannot use something like this:
$("body > *").not("body > #elementtokeep").remove();
因为 .not
函数不是我可以放在 .on()中的东西
function。
Because the .not
function is not something I can put inside the .on()
function.
我该如何实现?
推荐答案
不使用逗号同时拥有两个选择器:元素本身和元素子元素
Use not with a comma to have both selectors: the element itself and the elements children
jQuery(document.body).on("click", ":not(#calculator, #calculator *)", function(e){
console.log(this);
e.stopPropagation();
});
这篇关于jQuery点击除div之外的所有东西,它是孩子们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文