如何在按下美元键时找出按键或按键事件时按下的键

Ano*_*oop 3 javascript jquery keypress onkeyup

下面的方法返回来自AZ和0-9的任何键,当我按下shift键+ 4时,它返回相同的代码52.

function keyUpEvent(e)//onkeyup event
{
    var chr = String.fromCharCode(e.keyCode);//converts the keycode into a character
    alert(chr);//alerts the character
}
Run Code Online (Sandbox Code Playgroud)

但是当按下shift键组合的相应键时,我需要显示$或%.

Imp*_*ive 6

我会用这样的东西:

$(function () {
    $(document).on('keyup keydown keypress', function (event) {
        if (event.keyCode == 52 && event.shiftKey) {
            alert('foo');
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

的jsfiddle