获得焦点focus()使用example

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>title</title>
</head>
<script language="JavaScript">
   function test()
   {
     if(document.forms[0].elements[0].value.length==0)
     { alert("姓名不可以为空");
     document.forms[0].elements[0].focus();
     return false;
    }
    else if(document.forms[0].elements[1].value.length==0)
     { alert("密码不可以为空");
     document.forms[0].elements[1].focus();
      return false;
    }else {return true;}
   }
</script>
<body>
<form action="#" method="post" name="form1" onsubmit="return test();">
用户名<input type="text" name="name" >
密码<input type="password" name="password">
<input type="submit" value="提交">

</form></body>
</html>

你可能感兴趣的:(java,html,sql)