- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在网上看到的大部分代码都使用了document.onkeydown
,但是MDN只列出了window.onkeydown
. This comment还建议使用 window.onkeydown
。使用其中一个有什么区别或原因吗?
最佳答案
请参阅 Event dispatch and DOM event flow 中的下图:
一共有三个event phases :
The capture phase: the event object must propagate through the target's ancestors from the defaultView to the target's parent. This phase is also known as the capturing phase. Event listeners registered for this phase must handle the event before it reaches its target.
The target phase: the event object must arrive at the event object's event target. This phase is also known as the at-target phase. Event listeners registered for this phase must handle the event once it has reached its target. If the event type indicates that the event must not bubble, the event object must halt after completion of this phase.
The bubble phase: the event object propagates through the target's ancestors in reverse order, starting with the target's parent and ending with the defaultView. This phase is also known as the bubbling phase. Event listeners registered for this phase must handle the event after it has reached its target.
因此,主要区别在于,在冒泡阶段,添加到window
的事件监听器将在添加到document
的事件监听器之后处理事件;在捕获阶段之前。
关于javascript - window.onkeydown 和 document.onkeydown 有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27073074/
德尔福2010 我在主窗体上使用 OnFormKeyDown 事件,并且基本上在对话框上使用相同的事件 //主窗体 procedure TfrmMain.FormKeyDown(Sender: TOb
我在网上看到的大部分代码都使用了document.onkeydown,但是MDN只列出了window.onkeydown . This comment还建议使用 window.onkeydown。使用
我在线性布局中放置了一个 ListView ,我想覆盖 ListView 中的 onkeydown() 方法,我不控制焦点,只是改变onkeydown()中的一些变量,我希望系统像我没有覆盖onkey
我想知道如何使用事件监听器在 javscript 中正确使用 onkeydown 和 onkeyup 事件。我希望在您只需在网站中而不是在文本字段中按下时监听该事件。 我不确切地知道脚本会是什么样子,
我在从数字键盘输入数字值时遇到问题。我的脚本仅接受“qwerty”键上方数字键的数字。我想要的是用户还可以从数字键盘输入数字。以下是 HTML: 但是我尝试在 onkeypress 和
我不知道这个问题是否已经在某个地方得到了回答,但就是这样。 为什么会这样? el.onkeydown = function(e) { if(!((e.keyCode > 95 && e.keyCo
我不知道这个问题是否已经在某个地方得到了回答,但就是这样。 为什么会这样? el.onkeydown = function(e) { if(!((e.keyCode > 95 && e.keyCo
我在 if 语句中使用 var "str"时遇到问题。我知道这是一个范围问题,但我不知道如何解决它。我已经失败了好几次了。 我的目标是在 if 语句中使用“str”的值来显示或不显示警报。限制是我只能
当用户在 Android 中按下后退按钮时,我会出现一个自定义对话框,询问“您确定吗”。问题是,如果我实现 onKeyDown 方法,音量硬按钮就不起作用,并且音量不会升高或降低(在整个 Activi
我正在编写代码,以在按下音量调高/调低键时更改 TextView,以更新系统音量%设置的 TextView。我现在有这段代码,该代码可以工作一次,但它会覆盖调高/调低的功能,是有没有办法重写它或排除它
使用Material-UI Table我有这个: console.log(event)}> ... 当我用鼠标单击表格,然后开始单击向上和向下箭头键时,控制台上没有任何记录。我
设置左右箭头键图像导航脚本时遇到问题 document.onkeydown = function(event) { var e = event || wind
在我的旧项目中,我在 winform TextBox 中使用了 OnKeyPress 的覆盖来替换一些输入键 if(e.KeyChar == 'a') e.KeyChar = 'b'; // j
function Test(event) { console.log(event.key + ' ' + event.which + ' ' + event.code); } 结果: undef
这是我的代码 document.onkeydown = function (a) { if (a.which == 13) { alert("Not Anymore");
我正在处理一个表单并尝试创建一个执行以下操作的 onkeydown 函数: 仅在按下 tab 键 时触发(正常工作) 插入一个新元素(input)(一切正常) 然后插入的 input 调用相同的 on
我有一个无法识别第一次按键的 onKeyDown 事件(甚至无法进入该事件,我已经通过生成“toast”输出进行了测试)。在第二次按键和之后,它完美地工作。如果我点击屏幕上的另一个元素并再次尝试按键,
在我的应用程序中,我尝试覆盖 onKeyDown 方法并调用自定义对话框,但是当在设备上运行时,它没有显示该自定义对话框。我使用了调试器并看到调用了 onKeyDown 方法,但没有出现对话框并且应用
这个问题在这里已经有了答案: Override home and back button is case a boolean is true (6 个答案) 关闭 8 年前。 我覆盖了 Activi
public boolean onKeyDown(int keyCode, KeyEvent event) { } 此方法中的代码仅在选定的 EditText 具有退格键条目时触发。我需要它被任何类型
我是一名优秀的程序员,十分优秀!