javascript - How to write jquery to exclude an element and its sub-elements and select all other elements
伊谢尔伦2017-05-19 10:44:06
0
6
639
As shown in the picture, only clicking on the yellow and blue areas will execute the function. Clicking on the red area and the green sub-elements within the red will not execute the function. How to write it with jquery?
:not()
http://www.w3school.com.cn/cs...
var _sel = true;
$(".red",".green").click(function{
_sel = false;
})
$('.yellow','.blue').click(function(){
_sel = true;
})
if(_sel == true){
//执行函数
}
或者
要执行函数的有个公共的class
$(class).click(funciton(){
})
红色和绿色的没有这个class
最后我先写了个所有元素点击都执行的函数,在函数内判断点击的元素的className和元素的父元素有没有该className,如果为true,则不执行下面的内容
事件冒泡,event.target就可以了
有个siblings或许能解决这个...