我是 jquery 的新手。使用此代码,我认为很难看,任何人都可以帮助将其改进为更短的版本吗?因为实际代码是多于 6 个控件,为了方便您查看代码,我删除了其余部分。所以实际的代码更难看:(
$('#targetDay_0__Assigned , #targetDay_1__Assigned').hide();
if ($('#targetDay_0__Assigned').is(":checked")) {
$('#lbltargetDay_0__Assigned').addClass("ui-state-active");
}
if ($('#targetDay_1__Assigned').is(":checked")) {
$('#lbltargetDay_1__Assigned').addClass("ui-state-active");
}
$('#lbltargetDay_0__Assigned').click(function (e) {
$('#targetDay_0__Assigned').click();
$('#lbltargetDay_0__Assigned').removeClass("ui-state-active");
if ($('#targetDay_0__Assigned').is(":checked")) {
$('#lbltargetDay_0__Assigned').addClass("ui-state-active");
}
});
$('#lbltargetDay_1__Assigned').click(function (e) {
$('#targetDay_1__Assigned').click();
$('#lbltargetDay_1__Assigned').removeClass("ui-state-active");
if ($('#targetDay_1__Assigned').is(":checked")) {
$('#lbltargetDay_1__Assigned').addClass("ui-state-active");
}
});