jQuery keyboard operation analysis and simulation

1. Simulate keyboard operations through events (space bar as an example)

var e = jQuery.Event ( " keydown" ); //Simulate a keyboard event
 e.keyCode = 8 ; //keyCode=8 is the space
 $ ( this ) .trigger ( e ) ; // Simulate pressing the spacebar

2. Determine the operation of the keyboard (Enter key)
$('#id').keydown(function (event_e) {
    if (window.event) {
        event_e = window.event;
    }
    var int_keycode = event_e.charCode || event_e.keyCode;
    if (int_keycode == 13) {
        //TODO Enter key operation }
    
});


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325484319&siteId=291194637