一般情况下,不允许通过脚本来对文件上传框赋值。

下面是一个变通的方法。就是创建一个新的input type="file" 把原来的替换掉。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script type="text/javascript">
        function clearFile() {
            var oldFile = document.getElementById("fileID");
            var newFile = document.createElement("input");
            newFile.id = oldFile.id;
            newFile.type = "file";
            oldFile.parentNode.replaceChild(newFile, oldFile);
        }
    </script>
</head>
<body>
    <div>
    <input type="file" id="fileID" />
    <input type="button" value="clear file" onclick="clearFile()" />
    </div>
    </body>
</html>

 

相关文章:

  • 2021-11-30
  • 2022-03-11
  • 2022-12-23
  • 2023-01-21
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-31
  • 2022-02-25
  • 2022-02-09
  • 2021-07-31
  • 2021-11-30
相关资源
相似解决方案