请问大家如何删除input属性file值
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
</head>
<body>
<input type="file" id="myfile" />
<br /><br />
<input type="button" value="清空" id="clear" />
<script type="text/javascript">
$(function(){
$("#clear").click(function(){
var file = $("#myfile");
file.replaceWith(file.clone());
});
});
</script>
</body>
</html>
楼上的回答都好复杂,没必要那么复杂吧,顺手写了一段
http://jsbin.com/vuxaxedexi/e...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<form method="POST">
<input name="file" type="file" id="file">
<button type="button" id="clean">clean</button>
<button type="submit">submit</button>
</form>
</body>
</html>
let file = document.querySelector('#file');
let clean = document.querySelector('#clean');
clean.addEventListener('click', (ev) => {
file.value = null;
});
10 回答11.3k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.2k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
3 回答2.4k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
原来的移除掉,然后替换成相同的html