我想設置一個敲除的observable,將禁用輸入,如果兩個其他輸入不是都在1和30之間。現在,當我在jsFiddle中運行代碼時,我的輸入被禁用。不幸的是,我永遠無法重新啓用輸入。這裏是jsFiddle上的代碼感謝您的任何幫助。禁用基於其他輸入的輸入Knockoutjs
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());
韋德
謝謝布萊恩,不幸的是我只能接受一個答案,並與誰先回答。 – Wade73 2013-02-21 11:10:59