代码如下:
<!DOCTYPE html> <html> <meta charset="UTF-8"> <title></title> <head> <script language="javascript"> function checklogin() { if((myform.user.value != "")) { if((myform.pwd.value != "")) { return true } else { alert("密码不能为空"); return false } } else { alert("用户名不能为空"); return false } } </script> <title></title> </head> <body> <form action="form.html" name="myform" method="post" onSubmit="return checklogin()"> <input type="text" name="user" size="16"><br> <input type="password" name="pwd" size="16"><input type="submit" value="登录" name="sub_1"> </form> </body> </html>