[英]How to disable arrow keys?
我有模板视图(Extjs v6.5),其中导航内置了所有四个(左右上下)键,而我的视图就像一个垂直列表,所以我只想使用上下键并禁用左右键。
我尝试在 Ext JS 的itemKeyDown
事件上禁用按钮
this.addListener('itemkeydown', (me, record, item, index, e, eOpts) => {
if (e.keyCode === 37 || e.keyCode === 39) {
return false;
}
});
javascript按钮的keydown
事件无法实现。
this.el.dom.addEventListener('keydown', (e) => {
if (e.keyCode === 37 || e.keyCode === 39) {
return false;
}
});
还尝试e.preventDefault();
连同return false;
示例代码小提琴可以在这里找到
调用e.stopPropagation()
以防止键盘事件冒泡到父元素。
修改后的代码将捕获“ArrowRight”和“ArrowLeft”键。
function ignoreRightOrLeftKeys (e) {
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
e.stopPropagation();
console.log("itemkeydown stopped");
return false;
}
return true;
}
this.el.dom.addEventListener("keydown", (e) => {
console.log("keydown caught e:", e);
return ignoreRightOrLeftKeys(e);
});
this.addListener("itemkeydown", (me, record, item, index, e, eOpts) => {
console.log("itemkeydown caught e:", e);
return ignoreRightOrLeftKeys(e);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.