jquery select dropdown ignores keydown event when it's opened?

后端 未结 3 717
野趣味
野趣味 2020-12-20 20:44

I\'m trying to prevent backspace button to go one page back in every browser. For now I\'m using this code:

$(document).on(\"keydown\", function (e) {
    if         


        
3条回答
  •  时光取名叫无心
    2020-12-20 21:10

    Just add the select tag to your selector:

    $(document).on("keydown", function (e) {
        if (e.which === 8 && !$(e.target).is("input, textarea, select")) {
            e.preventDefault();
        }
    });
    

提交回复
热议问题