我已经在单选按钮列表上绑定“检查”和“点击”事件.但是,当单击单选按钮时,选择不会停留.我一定在做错事.真的很感激,如果你们能指出我正确的方向.
请参阅Fiddle Here
查看型号:
var viewmodel = { wantsSpam: ko.observable(true),spamFlavor: ko.observable('cherry'),click: function(model){ console.log(model); } };
视图:
<input type="radio" name="flavorGroup" value="cherry" data-bind="checked: spamFlavor,click:click" />
解决方法
从
click
event documentation:
By default,Knockout will prevent the
click
event from taking any default action.
…
However,if you do want to let the defaultclick
action proceed,justreturn true
from your click handler function.
所以你的单选按钮被重置,因为你的点击处理程序,并修复它只需要返回真的最后:
click: function(){ alert('Hi'); return true; }
演示JSFiddle.