如何以编程方式关闭选择文件对话框 [英] How to programmatically close select file dialog
问题描述
我有一个带有 type=file
的输入字段来选择一个图像文件,但我想要的是,如果有人打开文件选择器对话框,并且在某些特定事件中它会自动/以编程方式关闭对话框无需用户点击取消按钮.有没有办法用 js/jquery 做到这一点?
I have a input field with the type=file
to select an image file but what I want is that if someone opens the file selector dialog and on some particular event it automatically / programmatically closes the dialog without hitting the cancel button by the user. Is there any way to do it with js/jquery?
推荐答案
与 的交互非常有限.无法以编程方式关闭文件对话框.您可以尝试在对话框打开时通过处理
click
事件来禁用拖放功能;然而,似乎有没有可靠的跨浏览器在用户点击取消的情况下确定对话框已关闭的方法,因此重新启用它可能会很棘手.
Interaction with <input type="file" />
is very limited. There is no way to close the file dialog programmatically. You could potentially try to disable the drag/drop functionality while the dialog is open by handling the click
event; however, it seems that there is no reliable cross-browser method for determining that the dialog has been closed in a case where the user clicks cancel, so re-enabling it may be tricky.
不幸的是,如果用户选择从中拖放文件而不是使用打开"按钮,您可能只需要让用户自行关闭文件对话框.
Unfortunately, you will likely just have to let the user close the file dialog on their own if they choose to drag/drop files from it instead of using the "open" button.
这篇关于如何以编程方式关闭选择文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!