2 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊
你可以
為另一個(gè)復(fù)選框添加另一個(gè)可觀察對(duì)象
為按鈕添加一個(gè)計(jì)算的可觀察值,只有當(dāng)兩個(gè)復(fù)選框都被選中時(shí)才返回真(可觀察值是真的)
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貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊
您只能使用 CSS 來(lái)完成此操作。除非你需要支持 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>
添加回答
舉報(bào)