开发者

Suppress native keyboard events in Firefox (select tag)?

开发者 https://www.devze.com 2023-01-15 05:13 出处:网络
I\'m trying to suppress the normal keyboard events on Firefox\'s interpretation of the <select multiple="multiple"> box, but the methods I\'m used to aren\'t working. YUI\'s stopEvent

I'm trying to suppress the normal keyboard events on Firefox's interpretation of the <select multiple="multiple"> box, but the methods I'm used to aren't working. YUI's stopEvent doesn't seem to actually suppress the effects of a keypress or keydown (or both).

keyPressHandler = function (e) {
    YUE.stopEvent(e);
};
YAHOO.util.Event.addListener(element, 'keypress', keyPressHandler)
YAH开发者_运维技巧OO.util.Event.addListener(element, 'keydown', keyPressHandler)

Assuming element is a selectbox, the keyboard it still usable to navigate the selectbox in Firefox, however it is not in Chrome. Any ideas on how to properly suppress keyboard events in Firefox?

I generally don't step outside the bounds of YUI but if there is another solution I'm open to it.


Try this:

var keyPressHandler = function(e){
    e.preventDefault();  // prevents any default actions of the browser
    e.stopPropagation(); // prevents the event mechanism from bubbling
    return false;        // If there is any condition on the return value, assure it fails
};

element.addEventListener('keydown',keyPressHandler,false);
0

精彩评论

暂无评论...
验证码 换一张
取 消