如何清除文件输入 [英] How to clear File Input
本文介绍了如何清除文件输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我拥有的jQuery代码的一部分,其中显示了文件输入和一个清除文件"按钮.
Below is part of the jquery code I have which displays the file input and a "Clear File" button.
var $imagefile = $('<input />').attr({
type: 'file',
name: 'imageFile',
class: 'imageFile'
});
$image.append($imagefile);
var $imageclear = $('<input />').attr({
type: 'button',
name: 'imageClear',
class: 'imageClear',
value: 'Clear File'
});
$image.append($imageclear);
现在,我拥有清除文件"按钮的原因是,如果单击该按钮,它将清除文件输入中的所有内容.我该如何编码,以便当我单击清除文件"按钮时,它实际上清除了文件输入?
Now the reason I have the "Clear File" button is because if you click on the button, then it will clear anything that is in the file input. How do I code it so that it actually clears the file input when I click on the "Clear File" button?
推荐答案
这应该有效:
$imageClear.on('click', function() {
$imageFile.val('');
});
这篇关于如何清除文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文