我是否不正确地订阅了 YUI 菜单事件?

发布于 2024-07-06 16:12:50 字数 1034 浏览 11 评论 0原文

我已阅读并遵循YUI 的教程订阅菜单事件。 我还查看了菜单、菜单栏和自定义事件的 API 和代码位,但以下拒绝

// oMenuBar is a MenuBar instance with submenus
var buyMenu = oMenuBar.getSubmenus()[1];

// this works
buyMenu.subscribe('show', onShow, {foo: 'bar'}, false);

// using the subscribe method doesn't work
buyMenu.subscribe('mouseOver', onMouseOver, {foo: 'bar'}, false);

// manually attaching a listener doesn't work
YAHOO.util.Event.addListener(buyMenu, 'mouseOver', onMouseOver);

// http://developer.yahoo.com/yui/docs/YAHOO.widget.Menu.html#event_keyPressEvent        
// there is a keyPress Event, but no spelling of it will trigger the handler
buyMenu.subscribe('keypress', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keypressed', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keyPressed', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keyPress', onShow, {foo: 'bar'}, false);

功能上工作,我尝试为菜单栏的每个子菜单附加一个按键侦听器。 我不想添加 Bubbling 库作为依赖项。

I've read and followed YUI's tutorial for subscribing to Menu events. I also looked through the API and bits of the code for Menu, MenuBar, and Custom Events, but the following refuses to work

// oMenuBar is a MenuBar instance with submenus
var buyMenu = oMenuBar.getSubmenus()[1];

// this works
buyMenu.subscribe('show', onShow, {foo: 'bar'}, false);

// using the subscribe method doesn't work
buyMenu.subscribe('mouseOver', onMouseOver, {foo: 'bar'}, false);

// manually attaching a listener doesn't work
YAHOO.util.Event.addListener(buyMenu, 'mouseOver', onMouseOver);

// http://developer.yahoo.com/yui/docs/YAHOO.widget.Menu.html#event_keyPressEvent        
// there is a keyPress Event, but no spelling of it will trigger the handler
buyMenu.subscribe('keypress', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keypressed', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keyPressed', onShow, {foo: 'bar'}, false);
buyMenu.subscribe('keyPress', onShow, {foo: 'bar'}, false);

Functionally, I'm trying to attach a keyPress listener for each submenu of the MenuBar. I do not want to add Bubbling library as a dependency.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

野心澎湃 2024-07-13 16:12:50

这里是 Todd Kloots,YUI 菜单小部件的作者。 当您订阅基于 DOM 的事件时,事件名称全部小写。 因此,对于“mouseover”事件,请按如下方式订阅:

buyMenu.subscribe('mouseover', onMouseOver, {foo: 'bar'}, false);

关于您的按键事件处理程序:您订阅正确。 但是,请记住,任何与键相关的事件处理程序仅在菜单具有焦点时才会触发。 因此,在测试与按键相关的事件处理程序之前,请确保您的菜单具有焦点。 另外 - 我建议监听“keydown”事件而不是“keypress”,因为并非所有按键都会导致 IE 中的“keypress”事件触发。

如果您有任何其他问题,请直接访问 ydn-javascript Y! 分组,因为我经常监视该组上的消息。

我希望这有帮助。

  • 托德

Todd Kloots here, author of the YUI Menu widget. When you are subscribing to DOM-based events, the event name is all lower case. So, for the "mouseover" event, subscribe as follows:

buyMenu.subscribe('mouseover', onMouseOver, {foo: 'bar'}, false);

Regarding your keypress event handler: you are subscribing correctly. However, remember that any key-related event handlers will only fire if the Menu has focus. So, make sure your Menu has focus before testing your key-related event handlers. Also - I would recommend listening for the "keydown" event rather than "keypress" as not all keys result in the firing of the "keypress" event in IE.

If you have any other questions, please direct them to the ydn-javascript Y! Group as I monitor the messages on that group frequently.

I hope that helps.

  • Todd
A君 2024-07-13 16:12:50

根据我的测试,以下内容将起作用:

oMenu.subscribe('keypress', function () { alert("I'm your friendly neighborhood keypress listener.")});

但仅当 Menu 接收 keypress 事件时才会触发,因此它需要已经获得焦点。

Based on my testing, the following will work:

oMenu.subscribe('keypress', function () { alert("I'm your friendly neighborhood keypress listener.")});

but that only fires when the Menu is receiving the keypress event, so it would need to already have focus.

风吹雪碎 2024-07-13 16:12:50

onShow 是否指向一个函数?

例如。

var onShow = function()
{
    alert("Click!");
}

Does onShow point to a function?

eg.

var onShow = function()
{
    alert("Click!");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文