7

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?

4

4 に答える 4

0

No, there isn't a way to determine if the user clicked "Cancel" using the input="file" html element.

If you need more control over the file upload on a webpage, you can use Flash like Gmail does.

于 2012-06-13T12:04:37.793 に答える
0

No, but you can check if the value has changed (e.g. the user picked a file) using a listener for the change event.

Simple example:

HTML:

<input id=f type=file>

JavaScript:

function picked(){
    alert("Picked");                
}


$('#f').focus(function(evt){
    $(this).change(picked);   
});

View this example at jsFiddle

于 2012-06-13T12:14:25.560 に答える
-1

他の人が述べているように、入力アップロードタグはこれを行うことができません。

私はこのサードパーティのJSアップローダーを使用して良い経験をしました。Flashを使用しないため、モバイルデバイスにも適しています。

次の設定を行うことができます。

onCancel: function(id, fileName){}

初期設定呼び出しで。詳細については、Githubページの手順を参照してください。

于 2012-06-13T12:21:12.877 に答える
-3

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 says that:

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.

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 defines the behavior a little better, but again it does not talk about file selection process.

于 2012-06-13T12:02:39.233 に答える