2 回答

TA貢獻1789條經驗 獲得超10個贊
你可以
為另一個復選框添加另一個可觀察對象
為按鈕添加一個計算的可觀察值,只有當兩個復選框都被選中時才返回真(可觀察值是真的)
var test = {?
? myBoolean1: ko.observable(false),
? myBoolean2: ko.observable(false)
};
test.myComputed = ko.computed(function() { return test.myBoolean1() && test.myBoolean2() });
ko.applyBindings(test);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<input type="checkbox" data-bind="checked: myBoolean1" />
<input type="checkbox" data-bind="checked: myBoolean2" />
<button data-bind="enable: myComputed">My Button</button>

TA貢獻1856條經驗 獲得超11個贊
您只能使用 CSS 來完成此操作。除非你需要支持 IE10 或更低版本。
button {
cursor: not-allowed;
pointer-events: none;
color: grey;
background-color: white;
}
#firstCheckbox:checked+#secondCheckbox:checked+button {
color: black;
cursor: pointer;
pointer-events: auto;
}
<input type="checkbox" id="firstCheckbox">
<input type="checkbox" id="secondCheckbox">
<button>Click me</button>
添加回答
舉報