本段程式碼摘取自jquery.form.js中,由於覺得該方法的使用性非常強,同時也可獨立拿出來使用。
該段程式碼言簡意賅可以很好的作為學習參考。
});
};
$.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() {
.toLowerCase();
if (re.test(t) || tag == 'textarea') {
else if (t == ' checkbox' || t == 'radio') {
this.checked = false;
this.selectedIndex = -1;
}
else if (t == "file") {
$(this).replaceWith($(this).clone (true));
} else {
}
else if (includeHidden) {
// includeHidden can // includeHidden can be the value true, or it can be a selector string
// indicating a special test; for example:
🎜> / / the above would clean hidden inputs that have the class of 'special'
if ( (includeHidden === true && /hidden/.test()) ||
});
};