`
yuhui1988
  • 浏览: 9550 次
社区版块
存档分类
最新评论

清空file内容

 
阅读更多
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  
  <script type="text/javascript">
function clearFileInput(file){
	//no。1
    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);
	//no.2
	if (file.outerHTML) { // for IE, Opera, Safari, Chrome
file.outerHTML = file.outerHTML;
} else { // FF(包括3.5)
file.value = "";
}
}
</script >
 </head>

 <body>
<input name="file" type="file" id="file" />
<input name="button" type="button" onclick="clearFileInput(file)" value="清空" />
 </body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics