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

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

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

我该怎么做呢?


当前回答

如果你有以下情况:

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

然后就这样做:

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

重置文件控件。

其他回答

如果你有以下情况:

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

然后就这样做:

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

重置文件控件。

重置输入文件是非常单一的

$('input[type=file]').val(null);

如果你绑定重置文件中更改表单的其他字段,或者用ajax加载表单。

本例适用

选择器,例如$('input[type=text]')或表单的任何元素

事件单击,更改,或任何事件

$('body').delegate('event', 'selector', function(){
     $('input[type=file]').val(null) ;
});

函数重置图像字段() { var $el = $('#uploadCaptureInputFile'); $el.wrap('<form>').closest('form').get(0).reset(); $el.解包(); } <script src=“https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <input type=“file” id=“uploadCaptureInputFile” class=“win-content colors” accept=“image/*” /> <按钮点击=“重置图像字段()”>重置字段</button>

有许多方法,我将建议去参考附件输入。

<input
    id="image"
    type="file"
    required
    ref={ref => this.fileInput = ref}
    multiple
    onChange={this.onFileChangeHandler}
/>

在提交后清除值。

this.fileInput.value = "";

重置文件上传按钮是如此容易使用纯JavaScript!

有几个方法可以做到这一点,但必须直接的方法,这是在许多浏览器工作良好的改变文件值为零,这样上传文件得到重置,也尝试使用纯javascript而不是任何框架,我创建了下面的代码,检查一下(ES6):

函数resetFile() { const file = document.querySelector('.file'); 文件。Value = "; } <input type="file" class="file" /> <按钮onclick = " resetFile ()“>重置文件> < /按钮