这是我正在查看的文档:Example Adding Radio Buttons
它说:
KO will set the element to be checked if and only if the parameter value equals the radio button node’s value attribute
我在这方面所做的:jsfiddle
self.radioValue = ko.observable(1);
和 HTML:
<input type="radio" name="teloremail" value="1" data-bind="checked: radioValue" />
对我来说,这不会自动将 radio 设置为 checked
有什么原因吗?
最佳答案
单选按钮节点的 value
属性的类型是 string
,因此您还需要将值作为 string
存储在您的 observable 中:
self.radioValue = ko.observable("1");
演示 JSFiddle .
The example还使用字符串:"almond"
。
关于javascript - Knockout Js Radio Bindings 未设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127326/