문제

For example, I have an input tag like:

<input type="file" id="upload" multiple="true">

Is this possible to choose files by setting a hotkey instead of clicking on input element?

도움이 되었습니까?

해결책

$(document).on("keydown", function(e){
    e = e || window.event;
    var keyCode = event.keyCode;   // code of the key pressed

    if(e.ctrlKey){             // if control key is pressed
        if(keyCode == 13){     // if current key is "enter" key
            $("input[type='file']").trigger("click");  // trigger click event
        }
    }
});

DEMO

Here's a list of all key codes.

다른 팁

using document.keyup check out this fiddle, try clicking ctrl + i

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top