突然之间,以下代码在针对 KnockoutJS 3.0 时不再有效。我该如何解决这个问题?
JavaScript:
ko.bindingHandlers.limitCharacters = {
update: function(element, valueAccessor, allBindingsAccessor, viewModel)
{
element.value = element.value.substr(0, valueAccessor());
allBindingsAccessor().value(element.value.substr(0, valueAccessor()));
}
};
HTML:
<textarea data-bind="value: comment, valueUpdate: 'afterkeydown', limitCharacters: 20"></textarea>
见小提琴:http: //jsfiddle.net/ReQrz/1/