我想在自定义绑定中绑定 disabled 和 css,而不是使用 JQuery 来分配一个类并禁用它。您可以在自定义绑定中执行此操作而无需执行$(element).attr('disabled', true).addClass('disabled');
data_bind="enabled: classroomId(), css: { 'disabled' : !classroomId() }"
data_bind="disable: { !classroomId() }
ko.bindingHandlers.disable = {
update: function (element, valueAccessor) {
var disabled = ko.utils.unwrapObservable(valueAccessor());
// Disable and Add Class to Button or Anchor Tag
}
};