---
title: "js清空Form(基于jquery)"
author: "邪神Saber"
date: "2014-05-29T14:27:00Z"
tags: []
slug: "js-form-jquery"
draft: false
lastmod: "2014-06-30T15:10:05Z"
id: 2086717
url: "https://softblog.iteye.com/blog/2086717"
---

```
// 清空form表单
function clearForm(form) {
	$(':input', form).each(function() {
		var type = this.type;
		var tag = this.tagName.toLowerCase();
		if (type == 'text' || type == 'password' || tag == 'textarea') {
			this.value = "";
		} else if (type == 'checkbox' || type == 'radio') {
			this.checked = false;
		} else if (tag == 'select') {
			this.selectedIndex = -1;
		}
	});
};
```