質問

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