我需要为输入创建 keyPress (enter) 绑定。
<div id="body">
<input type="text" data-value-update="keyup" data-bind="value: text, keyPress: onKeyPress"/>
<div id="output"></div>
</div>
js:
kendo.data.binders.widget.keyPress = kendo.data.Binder.extend({
init: function (element, bindings, options) {
kendo.data.Binder.fn.init.call(this, element, bindings, options);
var binding = this.bindings.keyPress;
$(element.input).bind("keypress", function (e) {
if (e.which == 13) {
binding.get();
}
});
},
refresh: function () { }
});
var viewModel = kendo.observable({
text: '',
onKeyPress: function () {
$("#output").append("<div>keyPress</div>");
}
});
kendo.bind("#body", viewModel);
我有错误:
错误:输入元素不支持 keyPress 绑定
jsfiddle 中的示例http://jsfiddle.net/dude_jsfiddle/byA75/