以下聚合物元素具有一个按键事件监听器:
<polymer-element name="custom-element">
<template>
<input type="text" on-keypress="{{print}}" value="{{text}}">
</template>
<script type="application/dart" src="custom.dart"></script>
</polymer-element>
我希望元素侦听特定的按键类型(例如Enter,Backspace等)。这可能吗?
您不能只直接听特定的键代码,但是当然可以检查键代码并在侦听器中采取相应的措施:
// method name based on the template in the question
void print(Event e, var detail, Node target) {
int code = (e as KeyboardEvent).keyCode;
switch(code) {
case 13:
// this is enter
case 8:
// this is backspace, but not in keypress event
}
}
正如评论所说,您不能在中检查更多“高级”键on-keypress
,而必须使用on-keydown
或on-keyup
为此。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句