我正在用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/*" />
我该怎么做呢?
当前回答
var fileInput = $('#uploadCaptureInputFile');
fileInput.replaceWith(fileInput.val('').clone(true));
其他回答
<input type="file" id="mfile" name="mfile">
<p>Reset</p>
<script>
$(document).ready(function(){
$("p").click(function(){
$("#mfile").val('');
return false;
});
});
我用来做vuejs
<input
type="file"
ref="fileref"
@change="onChange"/>
this.$refs.fileref.value = ''
特别是对于Angular来说
document.getElementById('uploadFile').value = "";
会工作,但是如果你使用Angular呢 它会说“属性‘value’在类型‘HTMLElement’.any上不存在”
document.getElementById()返回不包含value属性的HTMLElement类型。因此,将它转换为HTMLInputElement
(<HTMLInputElement>document.getElementById('uploadFile')).value = "";
额外的:-
然而,我们不应该在angular中使用DOM操作(document.xyz())。
为此,angular提供了@ViewChild、@ViewChildren等,分别是document.querySelector()、document.queryselectorAll()。
连我都没读过。最好关注专家的博客
通过这个link1和link2
在IE 10中,我解决了这个问题:
var file = document.getElementById("file-input");
file.removeAttribute('value');
file.parentNode.replaceChild(file.cloneNode(true),file);
地点:
<input accept="image/*" onchange="angular.element(this).scope().uploadFile(this)" id="file-input" type="file"/>
jQuery的解决方案:
$('input').on('change',function(){
$(this).get(0).value = '';
$(this).get(0).type = '';
$(this).get(0).type = 'file';
});