【发布时间】:2020-01-02 14:11:16
【问题描述】:
当我通过选择文件按钮选择/取消选择文件时,它工作正常:
$("input[type='submit']").toggle(false);
$("input[type='file']").change(function() {
if ($(this).val() != "") {
$("#btn").toggle();
} else {
$("#btn").toggle();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="fld" type="file" name="image" id="file">
<input id="btn" type="submit" value="Upload / Edit picture" name="upload_picture" id="upload_picture" class="btn" />
<br>
<br>
<div id="remove_button">Remove</div>
单击“选择文件”按钮并选择一个文件。将出现上传/编辑图片按钮。现在再次单击选择文件按钮,但不要选择文件并退出小弹出窗口。上传/编辑图片按钮将消失。
在我的情况下,如果我通过单击 <div id="remove_button">Remove</div> 清除该值,我希望清除 input="file" 值,并且上传/编辑图片按钮消失
有没有办法做到这一点?
【问题讨论】:
-
这能回答你的问题吗? Clearing <input type='file' /> using jQuery
标签: javascript jquery html input