how to reset <input type = "file">

2022-08-29 23:06:46

I am developing a metro app with VS2012 and Javascript

I want to reset the contents of my file input:

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

How should I do that?


答案 1

The jQuery solution that @dhaval-marthak posted in the comments obviously works, but if you look at the actual jQuery call it's pretty easy to see what jQuery is doing, just setting the attribute to an empty string. So in "pure" JavaScript it would be:value

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

答案 2

You need to wrap in to tags and then you can reset input by resetting your form:<input type = “file”><form>

onClick="this.form.reset()"