我正在用VS2012和Javascript开发一个地铁应用程序
我想重置我的文件输入的内容:
<input type="file" id="uploadCaptureInputFile" class="win-content colors" accept="image/*" />
我该怎么做呢?
我正在用VS2012和Javascript开发一个地铁应用程序
我想重置我的文件输入的内容:
<input type="file" id="uploadCaptureInputFile" class="win-content colors" accept="image/*" />
我该怎么做呢?
当前回答
这是最好的解决方案:
input.value = ''
if(!/safari/i.test(navigator.userAgent)){
input.type = ''
input.type = 'file'
}
在所有的答案中这是最快的解。没有输入克隆,没有窗体重置!
我在所有浏览器中都检查了它(它甚至支持IE8)。
其他回答
@dhaval-marthak在评论中发布的jQuery解决方案显然是有效的,但如果你看看实际的jQuery调用,就很容易看出jQuery在做什么,只是将value属性设置为空字符串。所以在“纯”JavaScript中,它将是:
document.getElementById("uploadCaptureInputFile").value = "";
你应该试试这个:
$("#uploadCaptureInputFile").val('');
我用来做vuejs
<input
type="file"
ref="fileref"
@change="onChange"/>
this.$refs.fileref.value = ''
getElementById (uploadCaptureInputFile”)的文件。价值;
我在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 = '';`
};