How can I prevent Backspace from navigating back in javascript?

后端 未结 4 1316
天涯浪人
天涯浪人 2021-02-02 17:00

This works in IE, but I cannot get it to work in Opera or Firefox. I want to prevent Backspace from navigating away if and only if the current focus is the SELECT dropdown.

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 17:35

    Using jquery - for only select dropdown

    $(document).ready(function(){ 
         //for IE use keydown, for Mozilla keypress  
         //as described in scr: http://www.codeproject.com/KB/scripting/PreventDropdownBackSpace.aspx
         $('select').keypress(function(event){if (event.keyCode == 8) {return false;}});
         $('select').keydown(function(event){if (event.keyCode == 8) {return false;}});
    }
    

    For all elements in page except input controls and textarea is as follows

    
    

提交回复
热议问题