由于安全机制的问题,input[type=”file”]的值不能使用js进行修改,所以不能像其他表单元素那样进行重置。经过查阅资料后使用如下方法进行重置:
function resetInputFile(inputfile){
if(inputfile[0].value){
try{
inputfile[0].value="";
}catch(error){
}
if(inputfile[0].value){
var form = document.createElement('form');
var existingItem= inputfile.nextSibling;
var parent = inputfile.parentNode;
form.appendChild(inputfile);
form.reset();
parent.insertBefore(inputfile,existingItem);
}
}
}经过验证ie下无法使用,原因是:ie不允许在不同的文档中移动元素,所以form.appendchild(inputfile);这里会报错程序无法执行
以上就是如何清空input中[type="file"]的值 的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号