简体   繁体   English

将jQuery验证插件与以struts编写的表单一起使用

[英]Using jQuery validation plugin with a form written in struts

I want to implement the jQuery validation plugin for use in a web application written in java and struts. 我想实现jQuery验证插件,以用Java和Struts编写的Web应用程序中使用。 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. 我已经在一个简单的HTML表单上测试了它们,但是我没有如何使它们像上面的代码行那样与struts代码一起使用。

The fact that Struts is used to generate the form is irrelevant. 使用Struts生成表单的事实是无关紧要的。 JavaScript executes in the browser, and HTML is HTML. JavaScript在浏览器中执行,HTML是HTML。

The line of code above is not HTML. 上面的代码行不是HTML。 It's a Struts JSP tag that is evaluated at server-side and generates HTML code that is sent to the browser. 这是一个Struts JSP标记,在服务器端进行评估,并生成发送到浏览器的HTML代码。 jQuery only cares about the HTML. jQuery只关心HTML。 And the above code will generate the following HTML: 上面的代码将生成以下HTML:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM