Disable backspace and delete key with javascript in IE

前端 未结 4 738
面向向阳花
面向向阳花 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:23

    update based on @JoeCoders comment and the 'outdatedness' of my answer, I revised it.

    document.querySelector([text input element]).onkeydown = checkKey;
    function checkKey(e) {
        e = e || event;
        return !([8, 46].indexOf(e.which || e.keyCode || e.charCode) > -1);
    }
    

    See also this jsFiddle

提交回复
热议问题