我正在用VS2012和Javascript开发一个地铁应用程序

我想重置我的文件输入的内容:

<input type="file" id="uploadCaptureInputFile" class="win-content colors" accept="image/*" />

我该怎么做呢?


当前回答

jQuery的解决方案:

    $('input').on('change',function(){
                $(this).get(0).value = '';
                $(this).get(0).type = '';
                $(this).get(0).type = 'file';
            });

其他回答

你不能重置,因为它是一个只读文件。你可以克隆它来解决这个问题。

如果你的表单中有几个文件,但只想重置其中一个:

如果你使用boostrap, jquery, filstyle来显示输入文件的形式:

$("#"+idInput).filestyle('clear');

我的最佳解决方案

$(".file_uplaod_input").val('');  // this is working best ):

你应该试试这个:

$("#uploadCaptureInputFile").val('');

你可以克隆它,用它自己替换它,所有事件仍然附加:

<input type="file" id="control">

and

var input = $("#control");

function something_happens() {
    input.replaceWith(input.val('').clone(true));
};

谢谢:csstricks.com