问题
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