stopPropagation 不适用于 YUI 2.7 中的 KeyListener

发布于 2024-07-30 05:53:41 字数 883 浏览 4 评论 0原文

我创建了一个新的 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.stopPropagationYAHOO.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似梦非梦 2024-08-06 05:53:41

尝试这个:

 getDetailsLocalnameInput = function(e) {
     getDetails(localnameInput.value);

     if(window.event){
         e.cancelBubble=true;//In IE
     }else{
         evt.stopPropagation();//in Others
     }

     //YAHOO.util.Event.preventDefault(e);
     //YAHOO.util.Event.stopPropagation(e);
 };

Try this:

 getDetailsLocalnameInput = function(e) {
     getDetails(localnameInput.value);

     if(window.event){
         e.cancelBubble=true;//In IE
     }else{
         evt.stopPropagation();//in Others
     }

     //YAHOO.util.Event.preventDefault(e);
     //YAHOO.util.Event.stopPropagation(e);
 };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文