我是否不正确地订阅了 YUI 菜单事件?
我已阅读并遵循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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里是 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.
根据我的测试,以下内容将起作用:
但仅当
Menu
接收keypress
事件时才会触发,因此它需要已经获得焦点。Based on my testing, the following will work:
but that only fires when the
Menu
is receiving thekeypress
event, so it would need to already have focus.onShow 是否指向一个函数?
例如。
Does onShow point to a function?
eg.