2012-12-03 115 views
0

我有一個代碼(你可以在http://learn.knockoutjs.com/#/?tutorial=intro播放,單擊運行在輸出窗口前打):淘汰賽事件處理

HTML:

<div class="btn" style="margin-left: 15px;" data-bind="click: includeMyNumber"> 
    <input data-bind="checked: isIncludeMyNumber" data-val="true" id="IncludeMe" name="IncludeMe" style="margin: 0" type="checkbox" value="true" />&nbsp; 
    Include my number (+<span>11111111111</span>) 
</div> 

的Javascript:

// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI 
function AppViewModel() { 

    this.isIncludeMyNumber = ko.observable(false); 

    this.includeMyNumber = function(){ 
     this.isIncludeMyNumber(!this.isIncludeMyNumber()); 
    } 
} 

// Activates knockout.js 
ko.applyBindings(new AppViewModel()); 

問題是複選框單擊事件處理無法正常工作。當我點擊[div class =「btn」...] ... [/ div]區域內的空間時,複選框行爲是確定的,但是當我單擊複選框本身時,它不會被檢查。我怎樣才能在任何情況下進行檢查?

謝謝。

回答