stopPropagation 不适用于 YUI 2.7 中的 KeyListener
我创建了一个新的 YAHOO.util.KeyListener
来附加到特定元素,还创建了另一个新的 YAHOO.util.KeyListener
来附加到整个文档。 它们都与 enter 键(键:13)相关联。
在附加到特定元素的侦听器的处理函数中,我有以下代码:
getDetailsLocalnameInput = function(e) {
getDetails(localnameInput.value);
YAHOO.util.Event.preventDefault(e);
YAHOO.util.Event.stopPropagation(e);
};
然而,来自按键的事件继续传播到附加到整个文档的按键侦听器。 我不希望启动附加到整个文档的关键侦听器的处理程序。 我确信两个处理程序都被调用,但只希望附加到特定元素的处理程序运行。
将 YAHOO.util.Event.stopPropagation
与 YAHOO.util.KeyListener
一起使用是否正确?
我是否应该采取不同的方法来防止传播 keypress
事件?
我还尝试使用函数 YAHOO.util.Event.stopEvent
并设置 e.cancelBubble
但没有成功。
我已经用 Firefox 3.5 测试了所有这些。 我根本无法让 stopPropagation()
工作。
I have created a new YAHOO.util.KeyListener
to attach to a specific element and have also created another new YAHOO.util.KeyListener
to attach to the entire document. They are both associated with the enter key (keys:13).
In the handler function for the listener attached to the specific element, I have the following code:
getDetailsLocalnameInput = function(e) {
getDetails(localnameInput.value);
YAHOO.util.Event.preventDefault(e);
YAHOO.util.Event.stopPropagation(e);
};
Yet, the event from the keypress continues to propagate up to the key listener attached to the entire document. I do not want the handler for the key listener attached to the entire document to get kicked off. I am sure that both handlers are being called, but only want the handler attached to the specific element to run.
Is it correct to use YAHOO.util.Event.stopPropagation
with YAHOO.util.KeyListener
?
Is there a different way I should go about preventing the keypress
event from being propagated?
I have also tried using the function YAHOO.util.Event.stopEvent
and setting e.cancelBubble
with no success.
I have been testing all of this with Firefox 3.5. I cannot get stopPropagation()
to work at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个:
Try this: