2

我有一个奇怪的问题,我需要单击标签两次才能在下面选择单选按钮。选择后,我可以选择不同的并返回,然后单击即可使用原始版本。这只是每个单选按钮的初始点击,让我点击了两次。任何原因?

<label class="radio">
     <input type="radio" name="answer" data-bind="value: id, checked: $parent.answerId, disable: $parent.hasError()" /> <span data-bind="text: text"></span>
</label>
4

3 回答 3

1

我改用它来修复它,value: id().

于 2013-10-18T22:30:17.633 回答
1

I had exactly the same symptom: when clicking on a radio input the observable would get updated correctly, but the radio circle would only appear filled on the second click. I had only used the checked: binding, with no value: binding, and the value="" HTML attribute was set correctly.

The problem was that I had repeated the same markup twice in my page, and the HTML name="" attributes were not unique in the document. The solution was to remove the name="" HTML attributes altogether. They are not really needed if you are not submitting the form.

于 2018-05-15T14:14:42.200 回答
0

您正在使用一个值和一个选中的属性,但您只需要一个或另一个。

<label class="radio">
     <input type="radio" name="answer" data-bind="checked: $parent.answerId, disable: $parent.hasError()" /> <span data-bind="text: text"></span>
</label>

如果您使用检查,则很难将其设置为一组只有一个选择的单选按钮,因此您可能希望创建一个自定义的可观察对象来处理此处描述的值的读取和写入 -

http://knockoutjs.com/documentation/checked-binding.html

于 2013-10-18T18:04:44.990 回答