且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用键盘快捷键将文件上传到HTML5页面

更新时间:2023-12-02 23:44:28

你不能这样做。

你可以通过这个轻松获得文件路径:

You can get the file path easily with this :

$(document).on('paste',function(e){
    var path = e.originalEvent.clipboardData.getData("text");
});​

因此您可以向用户显示。

So you may show it to the user.

但你无法改变< input type = file> 的价值。

这是一个安全措施:想象一下,如果您的脚本可以在用户提交表单之前更改要上载的文件的路径(或者甚至没有用户交互,现在可以使用其他形式元素)?至于每个重要的安全保护,现代浏览器都没有已知的解决方法。

That's a security measure : imagine if your script could change the path of the file to be uploaded just before the user submits the form (or even without user interaction as is now possible with other form elements) ? As for every important security protection, there is no known "workaround" for modern browsers.