このEnter link description here anwserを見つけましたが、それは私にとっては良くありません.
「クリック」イベントをトリガーせずにモデル値を変更できるようにしたいと考えています。したがって、現在、ユーザーが値を変更すると(フィドルではありません)、一部のコードが「変更」イベントを生成します。しかし、モデルはその値を変更しません。
だから私は
モデル
function AppViewModel() {
//Common
this.TimeType = ko.observable(0);
}
$(document).ready(function () {
viewModel = new AppViewModel();
ko.applyBindings(viewModel, $("#testId")[0]);
$("#change").click(function () {
$("#third").attr('checked', 'checked');
$("#third").change();
alert(viewModel.TimeType());
});
});
HTML
<div id="testId" class="holder main-holder">
<div class="holder">
<input checked="checked" data-bind="checked: TimeType" id="Time" name="Type" type="radio" value="0"><label for="Time" class=" ">First</label>
</div>
<div class="holder">
</div><input data-bind="checked: TimeType" id="TimeWithTypeDay" name="Type" type="radio" value="1"><label for="TimeWithTypeDay">Second</label>
</div>
<div class="holder">
<input id="third" data-bind="checked: TimeType" id="TimeWithDaysOfWeek" name="Type" type="radio" value="2"><label for="TimeWithDaysOfWeek" >Third</label>
</div>
</div>
<input id="change" type="button" value ="Change"/>
フィドル: