我需要在单击Add Another按钮后启用Save Changes和Cancel Changes按钮。页面加载时已禁用“保存更改”按钮和“取消更改”按钮,但由于某些原因,单击通过后将无法启用。
{$().ready(function () {
$("#tabs").tabs();
$("#cancel-default").button().attr('disabled',true).addClass('ui-state-disabled');
$("#add-default").button();
$("#show-default-entry").button();
$("#save-all-defaults").button().attr('disabled', true).addClass('ui-state-disabled');
$(".ko-remove-link").button();
$("#saved-dialog-message").dialog({
autoOpen: false,
modal: true,
buttons: {
Ok: function () {
$("#saved-dialog-message").dialog('close');
}
}
});
var AdjustmentsViewModel = function() {
var self = this;
// properties
self.EmployeeId = $("#BaseEmployeeId").val();
self.Adjustments = ko.observableArray(initialData);
// methods
self.add = function (incoming) {
self.Adjustments.push(incoming);
};
self.remove = function (adjustment) {
self.Adjustments.remove(adjustment);
};
self.save = function () {
$.ajax({
url: '/Employee/AddAdjustmentDefaults',
crossDomain: true,
data: ko.toJSON(self),
contentType: "application/json; charset=utf-8",
dataType: 'json',
type: 'POST',
success: function (data) {
$("#saved-dialog-message").dialog("open");
},
error: function (error) { alert("Error."); },
always: function () { }
});
};
}
var viewModel = new AdjustmentsViewModel();
ko.applyBindings(viewModel);
$("#cancel-default").click(function () {
$("#show-default-entry").prop("disabled", false);
$("#entry-row").hide();
});
$("#show-default-entry").click(function () {
$("#show-default-entry").prop("disabled", true);
$("#entry-row").show();
});
$("#add-default").button().click(function () {
var record = {
"Id": "0",
"EmployeeId": $("#EmployeeId").val(),
"AdjustmentTargetTypeId": $("#TargetTypeId option:selected").val(),
"AdjustmentTargetId": $("#TargetId").val(),
"AdjustmentTargetTypeDescription": $("#TargetTypeId option:selected").text(),
"AdjustmentTargetDescription": $("#TargetId option:selected").text(),
"Amount": $("#Amount").val()
};
viewModel.add(record);
$("#show-default-entry").prop("disabled", false);
$("#entry-row").hide();
});
});
}
答案 0 :(得分:0)
尝试使用
$("#show-default-entry").attr("disabled", false);
答案 1 :(得分:0)
尝试 removeAttr()而不是 prop()
$('#my_selector').removeAttr('disabled');
使用此
$("#add-default").button().click(function () {
var record = {
"Id": "0",
"EmployeeId": $("#EmployeeId").val(),
"AdjustmentTargetTypeId": $("#TargetTypeId option:selected").val(),
"AdjustmentTargetId": $("#TargetId").val(),
"AdjustmentTargetTypeDescription": $("#TargetTypeId option:selected").text(),
"AdjustmentTargetDescription": $("#TargetId option:selected").text(),
"Amount": $("#Amount").val()
};
viewModel.add(record);
$("#show-default-entry").removeAttr('disabled'); //enables button
$("#cancel-default").removeAttr('disabled'); //enables button
$("#entry-row").hide();
});