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

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

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

我该怎么做呢?


当前回答

我的最佳解决方案

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

其他回答

如果你有以下情况:

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

然后就这样做:

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

重置文件控件。

@dhaval-marthak在评论中发布的jQuery解决方案显然是有效的,但如果你看看实际的jQuery调用,就很容易看出jQuery在做什么,只是将value属性设置为空字符串。所以在“纯”JavaScript中,它将是:

document.getElementById("uploadCaptureInputFile").value = "";

我在ng2-file-upload中遇到过angular的问题。如果你正在寻找angular的解决方案,请参考下面的代码

HTML:

<输入type=“文件”/>

组件

import {Component, OnInit, ElementRef, ViewChild} from @angular/core;

@ViewChild (activeFrameinputFile) InputFrameVariable: ElementRef;

this.frameUploader.onSuccessItem =(项目,响应,状态,头)=> {

`this.`**InputFrameVariable**`.nativeElement.value = '';`

};

在IE 10中,我解决了这个问题:

    var file = document.getElementById("file-input");
    file.removeAttribute('value');
    file.parentNode.replaceChild(file.cloneNode(true),file);

地点:

<input accept="image/*" onchange="angular.element(this).scope().uploadFile(this)" id="file-input" type="file"/>

我的最佳解决方案

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