简体   繁体   English

使用非选择器单击时的jQuery

[英]jquery on click with not selector

I have data which is loaded via ajax and I would like to disable a click event on li element which has a class active , the below is what I tried. 我有通过ajax加载的数据,并且我想禁用具有类active li元素上的click事件,这是我尝试的。 can someone help me out? 有人可以帮我吗?

$('body').on("click", 'li *:not(.active)', function (e) {
    //do something
}); //this doesn't work

You are targeting all non-active descendants of list items. 您以列表项的所有非活动后代为目标。

  • Remove the universal selector 卸下通用选择器
  • Remove the descendant combinator 删除后代组合器

Such: 这样:

'li:not(.active)'

If the active class is on the li then remove the space and * ( which targets all descendant elements that do not have the active class ) 如果active类位于li上,则删除空格和*它针对所有没有active类的后代元素

$('body').on("click", 'li:not(.active)', function (e) {
    //do something
}); //this doesn't work

Um, that code is not looking at an li element, thatmselector is looking for a child of an li element. 嗯,该代码未查看li元素,thatmselector正在查找li元素的子级。 Get rid of the space and * and it will check the li. 除去空格和*,它将检查li。

li:not(.active)

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

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