Key code check in Javascript not working for IE

前端 未结 2 698
感情败类
感情败类 2021-01-25 17:59

I tired to write a function to check key code with javascript. It\'s working fine for firefox but not IE. Does anyone know what is going wrong with my code? Please see below cod

2条回答
  •  自闭症患者
    2021-01-25 18:43

    switch your first line of code:

    ...

    var e = e || window.event;
    

    ...

    and see if that helps.

    Also, if it is a unicode character try something like the following:

    function displayunicode(e) {
        var unicode=e.keyCode? e.keyCode : e.charCode
        alert(unicode)
    }
    

    If you're handling keydown instead of keypress, then things get a bit more complex... See: http://unixpapa.com/js/key.html

提交回复
热议问题