JavaScript判断表单为空及获取焦点的方法
本文实例讲述了JavaScript判断表单为空及获取焦点的方法。分享给大家供大家参考,具体如下:
<%@ 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>javascript获得焦点</title> </head> <script language="JavaScript"> function aa() { 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="/ok.jsp" method="post" name="form1" onSubmit="return aa();"> 用户名<input type="text" name="name" > 密码<input type="password" name="password"> <input type="submit" value="提交"> </form> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。
相关推荐
learningever 2020-09-19
nercon 2020-07-26
运维工程师日记 2020-07-19
haohong 2020-07-18
dadaooxx 2020-07-04
行吟阁 2020-06-26
dadaooxx 2020-06-13
qsdnet我想学编程 2020-06-09
pythonclass 2020-06-07
pythonclass 2020-06-04
lyg0 2020-06-04
WebVincent 2020-06-03
niehanmin 2020-05-28
pythonclass 2020-05-09
gufudhn 2020-04-30
行吟阁 2020-04-18
swiftwwj 2020-03-08
nercon 2020-03-03