想实现的是选中系统设置后,下面的子项都选中。
js是这样写的:点击label,跟label对应的checkbox选中,然后通过样式让label打上勾

变成这样:

现在是选中了,但是对应的子项的勾没选中,反之则选中,请高手帮我看下这是什么原因,谢谢!
html:
-
-
js:
$('body').on('click','.privlist-grandparent',function(){
console.log($(this).siblings().prop("checked")); //返回false
if($(this).siblings().prop("checked")) {
$(this).parent().siblings().find('input[type="checkbox"]').prop('checked',true);
} else {
$(this).parent().siblings().find('input[type="checkbox"]').prop('checked',false);
}
})
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
子项是指公司管理 添加 编辑这些??
你提供的html布局不全,只是看到部分而已
那么,什么时候使用attr(),什么时候使用prop()?
1.添加属性名称该属性就会生效应该使用prop();
2.是有true,false两个属性使用prop();
3.其他则使用attr();