<html>
<title></title>
<script language="javascript">
function fun(){
if(form1.user.value=="")
{
alert("用户名不能为空!");
form1.user.focus();
return false;
}
if(form1.pwd.value=="")
{
alert("密码不能为空!");
form1.pwd.focus();
return false;
}
}
</script>
<body>
<form name="form1" action="check.jsp" method="post" onsubmit="return fun()" >
用户名:<input type="text" name="user"><br>
密 &nbsp;码:<input type="password" name="pwd"><br>
<input type="submit" value="提交" >
<input type="reset" value="重置">
  </form>
</body>
</html>
简单例子