我正在尝试设置一个可以禁用输入的淘汰赛 observable,如果其他两个输入不在 1 到 30 之间。现在当我在 jsFiddle 中运行代码时,我的输入被禁用。不幸的是,我永远无法重新启用输入。这是jsFiddle上的代码 感谢您的帮助。
HTML
<!-- This is a *view* - HTML markup that defines the appearance of your
UI -->
<p>Alcohol Days:
<input data-bind="value: alcoholDays" />
</p>
<p>Alcohol 5+ Days:
<input data-bind="value: alcoholFivePlusDays" />
</p>
<p>Alcohol 4- Days:
<input data-bind="value: alcoholFourLessDays" />
</p>
<p>Drug Days:
<input data-bind="value: drugDays" />
</p>
<p>Both Days:
<input data-bind="value: bothDays, enable: enableBothDays" />
</p>
<p>Enable Both Days: <strong data-bind="text: enableBothDays"></strong>
</p>
<p>Alcohol Days: <strong data-bind="text: alcoholDays"></strong>
</p>
<p>Drug Days: <strong data-bind="text: drugDays"></strong>
</p>
<button data-bind="click: capitalizeLastName">Go caps</button>
javascript
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
var self = this;
self.alcoholDays = ko.observable("");
self.alcoholFivePlusDays = ko.observable("");
self.alcoholFourLessDays = ko.observable("");
self.drugDays = ko.observable("");
self.bothDays = ko.observable("");
self.enableBothDays = ko.computed(function () {
if ((parseInt(self.alcoholDays) > 0 && parseInt(self.alcoholDays) <= 30) && (parseInt(self.drugDays) > 0 && parseInt(self.drugDays) <= 30)) {
return true;
} else {
return false;
}
}, self);
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
韦德