我們如何使文本可點擊。下面是一個被稱爲淘汰賽模板的列表。我可以直接選中該框,但無法使文本可點擊以便反映該複選框。
HTML:我如何使一個複選框的標籤在knockout js中可點擊?
<ul data-bind="template: { name: 'choiceTmpl', foreach: choices, templateOptions: { selections: selectedChoices } }"></ul>
<script id="choiceTmpl" type="text/html">
<li>
<input type="checkbox" data-bind="attr: { value: $data }, checked: $item.selections" />
<label data-bind="text: $data"></label>
</li>
</script>
JS:
var viewModel = {
choices: ["one", "two", "three", "four", "five"],
selectedChoices: ko.observableArray(["two", "four"])
};
viewModel.selectedChoicesDelimited = ko.dependentObservable(function() {
return this.selectedChoices().join(",");
}, viewModel);
ko.applyBindings(viewModel);
的jsfiddle演示:here
有什麼辦法,我們可以把它點擊?
您是否嘗試過給複選框和標籤相同的ID? –