Dropdown selection changed event

<select data-bind="options: choices, value: selectedChoice"></select>
<hr />
<select data-bind="event: { change: selectionChanged }">
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>
var viewModel = {
    choices: ["one", "two", "three"],
    selectedChoice: ko.observable("two") ,
    selectionChanged: function(event) {
         alert("the other selection changed");  
    } 
};

viewModel.selectedChoice.subscribe(function(newValue) {
   alert("the new value is " + newValue); 
});


ko.applyBindings(viewModel);

出处:http://jsfiddle.net/rniemeyer/LBz6d/

posted @ 2016-09-01 11:35  邹邹  Views(128)  Comments(0)    收藏  举报