部分代码如下:(java+struts)
<TR>
<TH align="left">ID</TH>
<TD><html:text property="customerID" name="IDForm"
maxlength="10" onkeypress="return checkChar(event)" /></TD>
<html:hidden property="customerID" />
</TR>
<TR>
<TH align="left">Password</TH>
<TD><html:text property="customerPassword"
name="IDForm" size="20" tabindex="2" maxlength="32"
style="width:100px;ime-mode:active" maxlength="16" /></TD>
</TR>
现在要实现的功能是点击页面上的“判断”按钮之后,在后台做判断,如果ID为空,就把焦点设在ID输入文本框上,如果Password为空,就把焦点设置在Password输入文本框上。这个功能怎么实现?
<TR>
<TH align="left">ID</TH>
<TD><html:text property="customerID" name="IDForm"
maxlength="10" onkeypress="return checkChar(event)" /></TD>
<html:hidden property="customerID" />
</TR>
<TR>
<TH align="left">Password</TH>
<TD><html:text property="customerPassword"
name="IDForm" size="20" tabindex="2" maxlength="32"
style="width:100px;ime-mode:active" maxlength="16" /></TD>
</TR>
现在要实现的功能是点击页面上的“判断”按钮之后,在后台做判断,如果ID为空,就把焦点设在ID输入文本框上,如果Password为空,就把焦点设置在Password输入文本框上。这个功能怎么实现?
网上好多js表单验证的例子
设置一个控件的焦点:
document.getElementById('控件Id').focus();例子:
检验表单提交的时候id为'id’的文本框不能为空:<%@ page ....%>
<html>
<head>
<title>xxx</title>
<script type="text/javascript">
function f(){
var s = document.getElementById('id').value;
if(s==""){
alert('不能为空');
document.getElementById('id').focus();
return false;
}
return true;
}
</script>
</head>
<body><form action="xxxAction.do" onSubmit="return f()"> //注意这里
<input type="text" id="id"/>
<input type="submit" value="提交"/>
</form></body>
</html>以上是直接用记事本手写的,可能有语法错误,但是主要意思应该表达清楚了,这是比较初等的做法。