Disable backspace and delete key with javascript in IE

前端 未结 4 723
面向向阳花
面向向阳花 2020-12-15 23:34

Anyone know how can I disable backspace and delete key with Javascript in IE? This is my code below, but seems it\'s not work for IE but fine for Mozilla.

on         


        
4条回答
  •  北海茫月
    2020-12-16 00:04

    This event handler works in all the major browsers.

    function onkeyup(e) {
        var code;
        if (!e) var e = window.event; // some browsers don't pass e, so get it from the window
        if (e.keyCode) code = e.keyCode; // some browsers use e.keyCode
        else if (e.which) code = e.which;  // others use e.which
    
        if (code == 8 || code == 46)
            return false;
    }
    

    You can attach the event to this function like:

    
    

提交回复
热议问题