来源:http://yuanyong.javaeye.com/blog/654292
<script>
function cleanFile(id){
var _file = document.getElementById(id);
if(_file.files){
_file.value ="";
}else{
if (typeof _file !="object"){ returnnull; }
var _span = document.createElement("span");
_span.id ="__tt__";
_file.parentNode.insertBefore(_span,_file);
var tf = document.createElement("form");
tf.appendChild(_file);
document.getElementsByTagName("body")[0].appendChild(tf);
tf.reset();
_span.parentNode.insertBefore(_file,_span);
_span.parentNode.removeChild(_span);
_span =null;
tf.parentNode.removeChild(tf);
}
}
</script>
<input id="file1" type="file"/>
<input type="button" value="清空" onclick="cleanFile('file1')"/>
function cleanFile(id){
var _file = document.getElementById(id);
if(_file.files){
_file.value ="";
}else{
if (typeof _file !="object"){ returnnull; }
var _span = document.createElement("span");
_span.id ="__tt__";
_file.parentNode.insertBefore(_span,_file);
var tf = document.createElement("form");
tf.appendChild(_file);
document.getElementsByTagName("body")[0].appendChild(tf);
tf.reset();
_span.parentNode.insertBefore(_file,_span);
_span.parentNode.removeChild(_span);
_span =null;
tf.parentNode.removeChild(tf);
}
}
</script>
<input id="file1" type="file"/>
<input type="button" value="清空" onclick="cleanFile('file1')"/>