将jQuery验证插件与以struts编写的表单一起使用 [英] Using jQuery validation plugin with a form written in struts

查看:144
本文介绍了将jQuery验证插件与以struts编写的表单一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现jQuery验证插件,以便用Java和Struts编写的Web应用程序中使用.我只想使用它来验证表单输入,以查看它们是否符合某些规则,然后再将其提交给数据库.我正在尝试实现的项目是由其他人编写的,我没有访问权限,也无法重写它.

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;"   />

我已经为插件编写了一些自定义方法.我已经在一个简单的HTML表单上对其进行了测试,但是我没有办法像上面的代码行那样使它们与struts代码一起使用.

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.

推荐答案

使用Struts生成表单的事实是无关紧要的. JavaScript在浏览器中执行,HTML是HTML.

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

上面的代码行不是HTML.这是一个Struts JSP标记,在服务器端进行评估,并生成发送到浏览器的HTML代码. jQuery只关心HTML.上面的代码将生成以下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;" />

这篇关于将jQuery验证插件与以struts编写的表单一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆