简体   繁体   中英

Jquery to javascript keypress event

I have the following in jquery code:

$(document).keypress(function (e) {
    if (e.keyCode == 13) {

    }
});

How can I make this into javascript so I do not need to load jquery everyime?

document.onkeypress = function (e) {
    if (!e) var e = window.event;
    var keyCode = e.keyCode || e.which;
    if(keyCode == 13) {

    }
    ...
}

Reading:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM