HTML / Javascript - stop left /right arrow from changing dropdown menu choice

前端 未结 4 627
醉梦人生
醉梦人生 2021-01-24 21:31

I am creating a web form with a grid of inputs for creating objects in Django.

It seems that when the focus is on a drop down menu, the up and left arrows select the pr

4条回答
  •  迷失自我
    2021-01-24 22:25

    IN regard to the answer of Ruud Lenders: works only if you have a single select in the form. If you have multiple select dropdowns then you can use the following version:

    $(document).on('keydown', 'select', function(event) {
        var value = $(this).find('option:selected').val();
        if ((event.which == 37 || event.which === 39)) {
            setTimeout(function (obj, val) {
                console.log(val)
                    return function() {
                        obj.find('option[value="' + val + '"]').prop("selected", true)
                    }
            }($(this), value), 0);
        }
    });
    

提交回复
热议问题