<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>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题 3</title>
</head>
<body>
<form name="form1" id="form1">
<input type="file" name="file1" size="35" value="12341"/><br>
<input type="file" name="file1" size="35" value="12341"/><br>
<input type="file" name="file1" size="35" value="12341"/><br>
<input name="btn" onclick="clear1()" type="button" value="点击我"/>
</form>
<script language="javascript" type="text/javascript">
function clear1()
{
var obj = document.getElementById('form1').file1[1]
obj.outerHTML = obj.outerHTML
document.getElementById('form1').file1[1].value=""
}
</script>
</body>
</html>
//主要理解clear方法中的内容就可以了