admin管理员组文章数量:1336633
I need to clear a file upload input field when the page loads. I have looked at 10-15 various ways to do this via stackoverflow, however every suggestion includes a reset button where I want to clear it on page load so that it is reset/cleared if a user clicks the back button on their browser.
I am currently using this code to reset the entire form, it works well for all of the dropdowns however it does not clear the file input field
function init() {
// Clear forms here
//reset inputs
$('#upload_form').trigger("reset");
//reset upload form
}
window.onload = init;
From my researh this seems to have the most upvotes from the munity Clearing <input type='file' /> using jQuery
Cheers!
I need to clear a file upload input field when the page loads. I have looked at 10-15 various ways to do this via stackoverflow, however every suggestion includes a reset button where I want to clear it on page load so that it is reset/cleared if a user clicks the back button on their browser.
I am currently using this code to reset the entire form, it works well for all of the dropdowns however it does not clear the file input field
function init() {
// Clear forms here
//reset inputs
$('#upload_form').trigger("reset");
//reset upload form
}
window.onload = init;
From my researh this seems to have the most upvotes from the munity Clearing <input type='file' /> using jQuery
Cheers!
Share edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked May 11, 2014 at 5:40 Ryan NZRyan NZ 6261 gold badge10 silver badges25 bronze badges2 Answers
Reset to default 5You don't need jQuery for that:
function init() {
document.getElementById("upload_form").reset();
}
window.onload = init;
One way to reset the file input type field is to replace it with a new one:
function reset() {
var input = document.querySelector('.file-input');
var newInput = input.cloneNode(true);
input.parentNode.replaceChild(newInput, input);
}
Example
http://jsfiddle/d25nV/
本文标签: javascriptClearReset file input on page loadStack Overflow
版权声明:本文标题:javascript - ClearReset file input on page load? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742401911a2468053.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论