如何实现新的按键事件以在 FF 中打开 `select` 元素的下拉菜单而不是默认的 Alt+down

How to implement new key events to open the drop-down for `select` element in FF instead of default Alt+down

我正在创建无障碍网站,用户可以在其中使用键盘访问网站上的控件。

HTML 的 select 元素可以使用 enter/Space 键下拉下拉菜单 Chrome 来访问,但相同的访问方式不同FF。我们想分别用Alt+up/Alt+down来关闭和打开下拉框

我想在 FF 中更改此行为并使其在浏览器中保持一致。因此,我想使用 Enter/Space 键进行控制访问,如 Chrome.

$('select').bind('keypress',function(event){
    if('MozBoxSizing' in document.body.style){
        if(event.which == 13 || event.which == 32){
            console.log("key pressed:" + event.which);
            $(this).trigger(click);
        }
    }
});

这是一个错误:

"key pressed:13" Util.js:38
ReferenceError: click is not defined Util.js:39
"key pressed:32" Util.js:38
ReferenceError: click is not defined

我怎样才能做到这一点?

无法在 fireFox

中更改 SELECT 的默认行为

你可以试试Jquery UI ComboBox

让您可以完全控制行为并根据需要进行更改。

https://jqueryui.com/autocomplete/#combobox

或者您可以尝试选择 2

https://select2.github.io/

如果您在自定义方面需要一些帮助,可以在这里发表评论,我将解释如何自定义这 2 个控件