Use Javascript to clear (reset) the value of the INPUT element of the file type, using criptinput
I have answered this question in StackOverflow before, and now I am sorting it out in my Blog.
Due to security restrictions, the script cannot set its value at will, so it cannot be reset with attributes like other form input fields.
There are three methods to reset the value of a file domain.
This article analyzes the browser compatibility and advantages and disadvantages of these three methods, and provides a perfect comprehensive solution code and Demo.
There are three methods to reset the file domain:
By combining method 1 and method 3, you can be compatible with all browsers.
The Javascript function code is as follows:
function clearInputFile(f){ if(f.value){ try{ f.value = ''; //for IE11, latest Chrome/Firefox/Opera... }catch(err){ } if(f.value){ //for IE5 ~ IE10 var form = document.createElement('form'), ref = f.nextSibling; form.appendChild(f); form.reset(); ref.parentNode.insertBefore(f,ref); } } }
View demo: http://jsbin.com/muhipoye/1/
How to use javascript to clear the value of type = text in input
I don't understand what I want to achieve. According to my understanding, there are two kinds of conjecture:
The first conjecture: when a user attempts to enter an invalid value in the text box, the user is not allowed to input, that is, the input is ineffective.
The second conjecture: before submitting a form, I want to clear all the text boxes and then submit them again?
I don't know which one are you talking about?
Clear the text box with javascript, and restore the default value in the text box
For example, <input type = "text" value = "$ {a}" id = "xx"/>
<Input type = "button" value = "go" onClick = "f ()">
<Script type = "text/javascript">
Function f (){
Var xx = document. getElementById ("xx ");
Xx. value = "";
}
</Script>