JQuery 点击整行后checkbox点击事件冲突解决


//绑定了li 或者tr这类元素,元素里的子元素有checkbox这中的的话会触发该点击事件和它自身点击事件导致没有选中  
$(".list").on("click",".item",function(){
    let children = $(this).children()["0"];
    console.log(children);
    if (children.checked) {
      children.checked = false;
    }
    else {
      children.checked = true;
    }
});
  解决方法
$( "input[type='checkbox']").click(function(e){
  e.stopPropagation();
});
如果是动态加载元素的话
$(".list").on("click","input[type='checkbox']",function(){
    e.stopPropagation(); 
 });


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM