问题描述
我有一个使用元素的文件API的html5应用程序.用户选择文件时,我能够做出响应.如果用户取消文件选择,我希望能够做一些事情.但是,如果用户单击文件选择器对话框中的取消"而不是确定"按钮,则找不到在输入元素上触发的事件.
I have a html5 application that makes use of the file API, using an element. I am able to respond when the user selects a file. I would like to be able to do something if the user cancels the file choice. However, I can find no event that is fired on the input element if the user clicks on the cancel rather than ok button in the file chooser dialogue.
我是否缺少某些在取消"上触发的事件,还是应该重新构建应用程序以使其不需要?
Is there some event fired on 'cancel' that I am missing, or should I re-architect my app to not need this?
推荐答案
当用户单击取消"时,更改事件触发器将再次触发.那对我有用;
When user clicks cancel, change event triggers again. Thats works for me;
$('#attachedFiles').bind("change", function () {
var file = this.files[0];
if (file) {
// if file selected, do something
} else {
// if user clicks 'Cancel', do something
}
});
这篇关于在输入类型=文件上捕获取消事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!