我正在用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/*" />
我该怎么做呢?
当前回答
你应该试试这个:
$("#uploadCaptureInputFile").val('');
其他回答
var fileInput = $('#uploadCaptureInputFile');
fileInput.replaceWith(fileInput.val('').clone(true));
我在这里错过了另一个解决方案(2021年): 我使用FileList与文件输入交互。
因为没有办法创建FileList对象,所以我使用DataTransfer,它带来了干净的FilleList。
我用:
file_input.files=new DataTransfer().files
在我的例子中,这非常适合,因为我只通过FileList与封装的文件输入元素进行交互。
有许多方法,我将建议去参考附件输入。
<input
id="image"
type="file"
required
ref={ref => this.fileInput = ref}
multiple
onChange={this.onFileChangeHandler}
/>
在提交后清除值。
this.fileInput.value = "";
这是最好的解决方案:
input.value = ''
if(!/safari/i.test(navigator.userAgent)){
input.type = ''
input.type = 'file'
}
在所有的答案中这是最快的解。没有输入克隆,没有窗体重置!
我在所有浏览器中都检查了它(它甚至支持IE8)。
我用来做vuejs
<input
type="file"
ref="fileref"
@change="onChange"/>
this.$refs.fileref.value = ''