清空上传控件(<input type="file"/>)值的方法

方法:创建一个新的form,把上传控件临时放过来,再调用这个form的reset方法,完工之后再把上传控件弄回去。这个form无需进入DOM结构便能正常工作,所以不用担心会对界面有任影响。下面给出函数实现,经过验证工作良好,呵呵。

//清空文件上传框
function clearFileInput(file){
    
var form=document.createElement('form');
    document.body.appendChild(form);
    
//记住file在旧表单中的的位置
    var pos=file.nextSibling;
    form.appendChild(file);
    form.reset();
    pos.parentNode.insertBefore(file,pos);
    document.body.removeChild(form);
}


相关文章:

  • 2021-09-20
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
猜你喜欢
  • 2021-12-15
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-09-03
  • 2021-07-25
  • 2021-09-30
相关资源
相似解决方案