js 清空file 值怎么清空

如题所述

第1个回答  2017-03-06
清空上传控件(<input type="file"/>)的值的两种方法

方法1:

<span id=span1>
<input name=ab type=file>
</span>
<input name=button1 type=button value="按" onclick=show()>

<script language=javascript>
function show()
{
document.getElementById("span1").innerHTML="<input name=ab type=file>";
}
</script>

方法2:

function clearFileInput(file){
var form=document.createElement('form');
document.body.appendChild(form);
//记住file在旧表单中的的位置
var pos=file.nextSibling;
form.appendChild(file);
form.reset();
pos.parentNode.insertBefore(file,pos);
document.body.removeChild(form);
}本回答被提问者采纳
第2个回答  2017-03-06
<form action="2.php" method="post">
<input type="file" name='a' class="a" id='op'>
<input type="submit" value='提交' class="b">
<a href="javascript:;" id='ap'>aa</a>
</form>
<a href="aaaaaa" id='hh'></a>
</body>
</html>
<script>

$(function(){
$('#ap').click(function(){
$('#op').val('');
});