我發現這個enter link description here anwser,但它對我沒有好處。敲除檢查綁定不會改變jquery「change」事件的模型值
我希望能夠更改模型值而不觸發「點擊」事件。所以現在當用戶改變值(不是小提琴)時,一些代碼會產生「改變」事件。但是模型並沒有改變它的價值。
所以我有一個
型號
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"/>
小提琴:
http://jsfiddle.net/skiff/4Wnmu/3/
你能請詳細說明'我想有改變模型值,而不觸發能力「單擊」 event.'? – gaurav
我有一個js的UI框架,它處理點擊和觸發更改事件。我不能改變它。所以我需要有能力查看視圖中的用戶更改模型 –