---
title: "form表单提交2次的原因"
author: "duyunfengsolo"
date: "2010-03-24T14:32:21Z"
tags: []
categories: ["Web前端"]
slug: "form-2"
draft: false
lastmod: "2010-03-24T14:32:21Z"
id: 623633
url: "https://solodu.iteye.com/blog/623633"
---

```
1.第一种写法：
(1)<form name="loginForm" action="login" method="post" id="loginForm">
<input type="button" value="tijiao" onclick="return checkField();"/>
</form>
(2)function checkField(){ 
if(usernameValue !== "" && passwordValue !== ""){
    	document.getElementById("loginForm").submit();    
    	return true;
    }
}
2.第二种写法：
(1)<input type="submit" value="tijiao" onclick="return checkField();"/>或者图片<input type="image" src="../images/btn-login.gif" alt="Login" class="btn-login" onclick="return checkField();"/>
(2)if(usernameValue !== "" && passwordValue !== ""){
                如果写了它就提交了2次。
    	//document.getElementById("loginForm").submit();    
    	return true;
    }
```