Jquery clear form data example sharing
This article mainly introduces the example of jquery clearing form data. For more information, see
The Code is as follows:
Function clearForm (form ){
// Iterate over all of the inputs for the form
// Element that was passed in
$ (': Input', form). each (function (){
Var type = this. type;
Var tag = this. tagName. toLowerCase (); // normalize case
// It's OK to reset the value attr of text inputs,
// Password inputs, and textareas
If (type = 'text' | type = 'Password' | tag = 'textea ')
This. value = "";
// Checkboxes and radios need to have their checked state cleared
// But shoshould * not * have their 'value' changed
Else if (type = 'checkbox' | type = 'Radio ')
This. checked = false;
// Select elements need to have their 'selectedindex 'property set to-1
// (This works for both single and multiple select elements)
Else if (tag = 'select ')
This. selectedIndex =-1;
});
};