测试环境:
OS --> winXP
Browsers --> IE6+, FF 3.0.11, FF 3.5, Opera 9.64, Opera 10 beta 2, Safari 4, Chrome 2.0.172
xhtml:
<input type="file" value="选择文件" id="fileInput" />
<button type="button" id="btnClear">清空文件域</button>
JS:
<script type="text/javascript">
var btn = document.getElementById("btnClear");
var file = document.getElementById("fileInput");
btn.onclick = function() {
// for IE, Opera, Safari, Chrome
if (file.outerHTML) {
file.outerHTML = file.outerHTML;
} else { // FF(包括3.5)
file.value = "";
}
}
</script>