我正在尝试抑制 Firefox 对 <select multiple="multiple">
的解释的正常键盘事件。框,但我习惯的方法不起作用。 YUI的stopEvent
似乎并没有真正抑制 keypress
的影响或keydown
(或两者)。
keyPressHandler = function (e) { YUE.stopEvent(e); }; YAHOO.util.Event.addListener(element, 'keypress', keyPressHandler) YAHOO.util.Event.addListener(element, 'keydown', keyPressHandler)
假设元素是一个选择框,键盘仍然可以在 Firefox 中用于导航选择框,但在 Chrome 中则不行。关于如何在 Firefox 中正确抑制键盘事件有什么想法吗?
我通常不会超出 YUI 的范围,但如果有其他解决方案,我愿意接受。
最佳答案
试试这个:
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);
关于javascript - 抑制 Firefox 中的 native 键盘事件(选择标签)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3653852/