一般情况下,不允许通过脚本来对文件上传框赋值。下面一个变通的方法。就是创建一个新的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>