防止表单重复提交

时间:2022-09-12 16:46:48

方法一

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>login.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>

<body>
<form id="f1" action="/day06/servlet/ReLoginServlet" method="post">
用户名:<input type="text" name="username"/><br/>
密码:<input type="password" name="password"/><br/>
<input id="btn" type="button" value="登陆" onclick="doSomething()"/>
</form>
<script type="text/javascript">
function doSomething(){
//得到button对象
var btnObj = document.getElementById("btn");
//让该按钮变为灰色
btnObj.disabled="true";
//表单提交
document.getElementById("f1").submit();
}
</script>
</body>
</html>

防止表单重复提交