Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换jquery中的类时,会停止元素执行所需的操作_Jquery_Css - Fatal编程技术网

替换jquery中的类时,会停止元素执行所需的操作

替换jquery中的类时,会停止元素执行所需的操作,jquery,css,Jquery,Css,我有一个类别列表,你只能选择一个。选定的过滤器有一个类,当选择其他过滤器时,选定的过滤器将丢失其选定的类,并返回到非选定过滤器。但是,一旦发生这种情况,我就不能再单击元素来添加类 $('.bpcustomers\u not\u selected')。单击(函数(){ $(this).parent().find('.bpcustomers_selected').removeClass('bpcustomers_selected').addClass('bpcustomers_not_select

我有一个类别列表,你只能选择一个。选定的过滤器有一个类,当选择其他过滤器时,选定的过滤器将丢失其选定的类,并返回到非选定过滤器。但是,一旦发生这种情况,我就不能再单击元素来添加类

$('.bpcustomers\u not\u selected')。单击(函数(){
$(this).parent().find('.bpcustomers_selected').removeClass('bpcustomers_selected').addClass('bpcustomers_not_selected');
$(this).removeClass('bpcustomers\u not\u selected').addClass('bpcustomers\u selected');
});
.bpcustomers\u过滤器li{
光标:指针;
填充:10px0;
}
.bpcustomers\u未选中:悬停{
颜色:#000;
}
.BPU已选定{
颜色:#2585fe;
字体大小:粗体;
}

  • 所有
  • 低于1000英镑
  • 1000-10000英镑
  • 10000-25000英镑
  • 25000-50000英镑
  • 超过50000英镑
只需更改


$('.bpcustomers\u not_selected')。单击(function(){
问题是,当您绑定onClick事件时,ALL没有目标类。因此,onClick永远不会为该LI触发

我建议给每个项目一个类,然后您可以使用它来定位点击,只需在点击时附加和删除一个“选定”类

e、 g


由于ALL最初没有选择
bpcustomers\u
类,并且您正在动态添加它,因此需要在
bpcustomers\u过滤器中使用,如下所示:

$('.bpcustomers\u filter')
.on('click','bpcustomers\u not\u selected',function(){
$(this).parent().find('.bpcustomers_selected').removeClass('bpcustomers_selected').addClass('bpcustomers_not_selected');
$(this).removeClass('bpcustomers\u not\u selected').addClass('bpcustomers\u selected');
});
.bpcustomers\u过滤器li{
光标:指针;
填充:10px0;
}
.bpcustomers\u未选中:悬停{
颜色:#000;
}
.BPU已选定{
颜色:#2585fe;
字体大小:粗体;
}

  • 所有
  • 低于1000英镑
  • 1000-10000英镑
  • 10000-25000英镑
  • 25000-50000英镑
  • 超过50000英镑

也许你应该考虑使用<代码> $('.bpCuuleSsNoToNeXield')。(点击)< /C> >而不是<代码> $('.bpCuuleSsNoToNoLead)。当您有动态内容时,单击
。我想这是执行相同操作的不同语法。您将单击事件应用于所有
。bpcustomers\u未选中
,但在您的JSFIDLE中,all没有加载此类,因此在()工作很好,我正在考虑尝试它,因为我需要确定其他操作的类
$('.all-my-lis').click(function(){
    $('.all-my-lis').removeClass('selected');
    $(this).addClass('selected');
});