我发现了一个疯狂的解决方案,用于处理未选中或未选中的复选框问题,这是我的算法...创建一个全局变量,可以说var check_holder
check_holder有3个状态
- 未定义状态
- 0状态
- 1个州
如果选中该复选框,
$(document).on("click","#check",function(){
if(typeof(check_holder)=="undefined"){
//this means that it is the first time and the check is going to be checked
//do something
check_holder=1; //indicates that the is checked,it is in checked state
}
else if(check_holder==1){
//do something when the check is going to be unchecked
check_holder=0; //it means that it is not checked,it is in unchecked state
}
else if(check_holder==0){
//do something when the check is going to be checked
check_holder=1;//indicates that it is in a checked state
}
});
上面的代码可在许多情况下用于查找是否已选中复选框。其背后的概念是将复选框状态保存在变量中,即打开或关闭时。我希望该逻辑可以用来解决您的问题。
.click()
click事件的函数。因此,我不理解您所说的“启用”和“禁用”是什么意思。如果选中此复选框,则可以调用functiona()
。但是您必须编写反向功能以在未选中此复选框时调用。我很困惑。