javascript 取消文件上传 - 监听器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11014384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cancel file upload - listener?
提问by panthro
Possible Duplicate:
“On file dialog cancel” event in JavaScript
Is there a listener for when a user clicks cancel instead of done on a file upload dialog box?
当用户单击取消而不是在文件上传对话框上完成时,是否有侦听器?
采纳答案by joshschreuder
As others have mentioned, the input upload tag can't do this.
正如其他人所提到的,输入上传标签不能这样做。
I have had good experiences using this 3rd party JS uploader. It doesn't use Flash so is suitable for mobile devices also.
我在使用这个 3rd 方 JS 上传器方面有很好的经验。它不使用 Flash,因此也适用于移动设备。
You can set:
您可以设置:
onCancel: function(id, fileName){}
In the initial setup call. See the instructions on the Github page for more details.
在初始设置调用中。有关更多详细信息,请参阅 Github 页面上的说明。
回答by jorgebg
No, there isn't a way to determine if the user clicked "Cancel" using the input="file" html element.
不,没有办法确定用户是否使用 input="file" html 元素单击了“取消”。
If you need more control over the file upload on a webpage, you can use Flash like Gmail does.
如果您需要更多地控制网页上的文件上传,您可以像 Gmail 一样使用Flash。
回答by user2428118
No, but you can check if the value has changed (e.g. the user picked a file) using a listener for the change
event.
否,但您可以使用change
事件的侦听器检查值是否已更改(例如,用户选择了一个文件)。
Simple example:
简单的例子:
HTML:
HTML:
<input id=f type=file>
JavaScript:
JavaScript:
function picked(){
alert("Picked");
}
$('#f').focus(function(evt){
$(this).change(picked);
});
回答by naivists
Most likely it depends on the browser. Some browsers might allow you catch this. Other browsers might not. This is because HTML standard does not explicitly state how a file upload control should look like or how the file selection has to be implemented. It just saysthat:
很可能这取决于浏览器。某些浏览器可能允许您捕捉到这一点。其他浏览器可能不会。这是因为 HTML 标准没有明确说明文件上传控件的外观或必须如何实现文件选择。它只是说:
This control type allows the user to select files so that their contents may be submitted with a form. The INPUT element is used to create a file select control.
此控件类型允许用户选择文件,以便可以通过表单提交其内容。INPUT 元素用于创建文件选择控件。
Browser developers may choose how they allow you to select files. It may be a pop-up window, it may as well be a list of all files in your computer/device which you have to pick from.
浏览器开发人员可以选择他们允许您选择文件的方式。它可能是一个弹出窗口,也可能是您必须从中选择的计算机/设备中所有文件的列表。
HTML5 definesthe behavior a little better, but again it does not talk about file selection process.