Using jQuery validation plugin with a form written in struts

ぐ巨炮叔叔 提交于 2019-12-11 17:40:13

问题


I want to implement the jQuery validation plugin for use in a web application written in java and struts. I just want to use it to validate form inputs to see if they conform to certain rules before it's submitted to a database. The project I'm trying to implement this in was written by someone else, I don't have access to them, and I can't rewrite it.

Here is one of the form inputs that I want to validate:

<html:text property="groomFirstName" maxlength="30" tabindex="1" styleId="groomFirstName"  size="15" onchange="properCase(this.id); needToConfirm=true;"   />

I've written some custom methods for the plugin. I have tested them on a simple HTML form, but I don't how to make them work with the struts code like the line of code above.


回答1:


The fact that Struts is used to generate the form is irrelevant. JavaScript executes in the browser, and HTML is HTML.

The line of code above is not HTML. It's a Struts JSP tag that is evaluated at server-side and generates HTML code that is sent to the browser. jQuery only cares about the HTML. And the above code will generate the following HTML:

<input type="text" name="groomFirstName" maxlength="30" tabindex="1" 
       id="groomFirstName" size="15" 
       onchange="properCase(this.id); needToConfirm=true;" />


来源:https://stackoverflow.com/questions/10758729/using-jquery-validation-plugin-with-a-form-written-in-struts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!