This code is excerpted from jquery.form.js. Because I think this method is very useful, it can also be used independently.
This code snippet is concise and can be used as a good reference for learning.
$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel |text|time|url|week)$/i; // 'hidden' is not in this list
return this.each(function() {
var t = this.type, tag = this.tagName .toLowerCase();
checkbox' || t == 'radio') {
this.checked = false;
}
else if (tag == 'select') {
this.selectedIndex = -1;
}
if (/msie/.testck.com)) {
$ (this) .Replacewith ($ (this) .clone (true));
// includeHidden can be the value true, or it can be a selector string
/ the above would clean hidden inputs that have the class of 'special'
if ( (includeHidden === true && /hidden/.test(t)) ||
(typeof includeHidden == 'string' && $(this).is(includeHidden)) ) {
this.value = '';