本文實(shí)例講述了JavaScript判斷表單為空及獲取焦點(diǎn)的方法。分享給大家供大家參考,具體如下:
<%@ 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獲得焦點(diǎn)</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程序設(shè)計(jì)有所幫助。



















