代码如下:
<script language="javascript"> /** * 删除input属性为file的值 * http://www.jb200.com */ function cleanFile(id){ var _file = document.getElementById(id); if(_file.files) { _file.value = ""; }else{ if (typeof _file != "object") return null; 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>
经测试,以上代码真实有效,可以使用!