第一种
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form action="login.do?act=login" method="post" style="text-align: center;width:260px;padding:60px;margin:0 auto;background: pink;">
- <p > 用户帐号:<input type=text name="userId" size="18" value=""></p>
- <p > 登录密码:<input type="password" name="password" size="18" value="" /><p/>
- <p><input type=submit name="submit1" value="登陆" onclick="return check(this.form)"></p>
- </form>
- </body>
- <script type="text/javascript">
- function check(form) {
- if(form.userId.value == '') {
- alert("请输入用户帐号!");
- form.userId.focus();
- return false;
- }
- if(form.password.value == '') {
- alert("请输入登录密码!");
- form.password.focus();
- return false;
- }
- return true;
- }
- </script>
- </html>
第二种
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form action="login.do?act=login" method="post" onsubmit="return check(this)" style="text-align: center;width:260px;padding:60px;margin:0 auto;background: aqua;">
- <p > 用户帐号:<input type=text name="userId" size="18" value=""></p>
- <p > 登录密码:<input type="password" name="password" size="18" value="" />
- <p/>
- <p><input type=submit name="submit1" value="登陆"></p>
- </form>
- </body>
- <script type="text/javascript">
- function check(form) {
- if(form.userId.value == '') {
- alert("请输入用户帐号!");
- form.userId.focus();
- return false;
- }
- if(form.password.value == '') {
- alert("请输入登录密码!");
- form.password.focus();
- return false;
- }
- return true;
- }
- </script>
- </html>
第三种
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <form action="login.do?act=login" name="myform" method="post" style="text-align: center;width:260px;padding:60px;margin:0 auto;background:plum;">
- <p > 用户帐号:<input type=text name="userId" size="18" value=""></p>
- <p > 登录密码:<input type="password" name="password" size="18" value="" />
- <p/>
- <p><input type=button name="submit1" value="登陆" onclick="check(this.form)"></p>
- </form>
- </body>
- <script type="text/javascript">
- function check(form) {
- if(form.userId.value == '') {
- alert("请输入用户帐号!");
- form.userId.focus();
- return false;
- }
- if(form.password.value == '') {
- alert("请输入登录密码!");
- form.password.focus();
- return false;
- }
- document.myform.submit();
- }
- </script>
- </html>
来源: http://www.qdfuns.com/article/40816/802d13b3bf0d8b8ee80ab1226c929f65.html