日期:2014-05-18  浏览次数:20636 次

至急:(Struts中验证validator)如何在验证后改变jsp中验证出错文本的背景色?
Struts中验证validator
一般的方法是直接将error写到页面上,但是如果想告诉客户哪个地方出错,要将出错地方的颜色改变,请问是否可行?能不能提供代码?
各位大虾,请多帮助啊!!
在线等待中,请指教...........
多谢了!!!

------解决方案--------------------
可以,用css,error时设定成你需要的颜色
------解决方案--------------------
就设置error的css属性就可以了,只有出错的时候这个error标签才会出来。
------解决方案--------------------
那你还不如就在每一个文本框后面加一个 <font color= "red "> <html:errors/> </font>
当出现错误的时候就会在相应的文本框后面提示错误信息。这也是strtus固有格式
------解决方案--------------------
<logic:messagesPresent>
<textarea name= "textareaError " cols= "60 " rows= "4 " class= "textareaError " readonly > <html:errors /> </textarea>
</logic:messagesPresent>

这样就把所有的错误信息都写在textarea中

<% String bgcolor = " "; %>
<logic:messagesPresent property= "username ">
<% stylerror = "yellow "; %>
</logic:messagesPresent>
<td> <input type= "text " name= "username " size= "15 " maxlength= "8 " value= " " autocomplete= "off " bgcolor= " <%=bgcolor%> "/> </td>



------解决方案--------------------
var errBgColor = "yellow "

var errmsg01= ' ';
<html:messages id= 'msg ' message= 'false '>
errmsg01 = errmsg01 + " <bean:write name= 'msg ' /> " + " <BR> "
</html:messages>
if (errmsg01!= ' ') {
outmsg(errmsg01);
<%
Iterator errProp = ((ActionMessages)request.getAttribute(Globals.ERROR_KEY)).properties();
while(errProp.hasNext()){
%>
ChangeBackGroundColor( " <%=errProp.next()%> ", errBgColor)
<% } %>
}

通过这个方法把所有出错的项目都改变被景色
------解决方案--------------------
form.username.style.backgroundColor= "red ";
form.password.style.backgroundColor= "red ";

在你验证到错误的js中加入上面的代码就可以了