我正在用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/*" />
我该怎么做呢?
当前回答
我在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 = '';`
};
其他回答
如果你的表单中有几个文件,但只想重置其中一个:
如果你使用boostrap, jquery, filstyle来显示输入文件的形式:
$("#"+idInput).filestyle('clear');
也适用于动态控制。
Javascript
<input type="file" onchange="FileValidate(this)" />
function FileValidate(object) {
if ((object.files[0].size / 1024 / 1024) > 1) { //greater than 1 MB
$(object).val('');
}
}
JQuery
<input type="file" class="UpoloadFileSize">
$(document).ready(function () {
$('.UpoloadFileSize').bind('change', function () {
if ((this.files[0].size / 1024000) > 1.5) { //greater than 1.5 MB
$(this).val('');
alert('Size exceeded !!');
}
});
});
你需要将<input type = " file " >包装成<form>标签,然后你可以通过重置你的表单来重置输入:
onClick="this.form.reset()"
var fileInput = $('#uploadCaptureInputFile');
fileInput.replaceWith(fileInput.val('').clone(true));
我在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 = '';`
};