JQuery Form Validator插件无法正常工作

时间:2011-06-05 14:07:00

标签: jquery html

我正在尝试使我的jQuery表单验证器工作。我已经花了5个小时使它工作,研究和填充,但直到现在我不能。

我的代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="style.css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
  <script>
        $(document).ready(function(){
            $("#formID").validationEngine();
        });
  </script>

</head>
<body>
    <div id="headerBar" ><h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The Book of Joy!</h1></div>
    <div id="content" align="center">
    <div id="contentText" align="center">Be a part of our team of IT experts. Apply now!</div>
        <div id="leftContent" align=center></div>
        <div id="rightContent" align=left>
        <b>Signup now!</b>
        <hr>

            <form  id="formID" method = "post" action = "AddApplicantServlet"> 
                <fieldset>
                    <legend id="legendid">Applicant Registration Form</legend>
                    <table>
                        <tr><td>First Name:               </td><td><input type = "text" name = fName class="validate[required,custom[onlyLetterSp]]">           </td></tr>
                        <tr><td>Middle Name:              </td><td><input type = "text" name = mName class="validate[required,custom[onlyLetterSp]]">           </td></tr>
                        <tr><td>Last Name:                </td><td><input type = "text" name = lName class="validate[required,custom[onlyLetterSp]]">           </td></tr>
                        <tr><td>Age:                      </td><td><input type = "text" name = age   class="validate[required,custom[onlyNumberSp]],maxSize[2]">  </td></tr>
                        <tr><td>Gender:                   </td><td><select name = gender><option value='m'>Male</option><option value='f'>Female</option> </select>  </td></tr>
                        <tr><td>Email Address:            </td><td><input type = "text" name = email class="validate[required,custom[email]]">        </td></tr>
                        <tr><td>Contact No:               </td><td><input type = "text" name = contactNumber class="validate[required]"></td></tr>
                        <tr><td>City of Residence:        </td><td><input type = "text" name = city   class="validate[required]">         </td></tr>
                        <tr><td>School:                   </td><td><input type = "text" name = school class="validate[required]">       </td></tr>
                        <tr><td>Course:                   </td><td><input type = "text" name = course class="validate[required]">       </td></tr>
                        <tr><td>Year Graduated:           </td><td><input type = "text" name = yearGraduated class="validate[required,custom[onlyNumberSp]],maxSize[4]"></td></tr>
                        <tr><td>Previous Work Experience: </td><td><input type = "text" name = yearWorkExp class="validate[required,custom[onlyNumberSp]],maxSize[2]">  </td></tr>
                        <tr><td>Sourcing Channel:         </td><td><select name = sourceChannel> 
                            <option value='Jobstreet'>Jobstreet</option>
                            <option value='Direct'>Direct</option>
                            <option value='Referral'>Referral</option>
                            <option value='Board Exam'>Board Exam</option>
                            <option value='Oath Taking'>Oath  Taking</option>
                            <option value='GradList'>GradList</option> 
                         </select></td></tr>
                            <tr><td> <input type = "submit" value = SUBMIT></td></tr>
                    </table>
                </fieldset>
            </form>
            <hr>
        </div>
    </div>

为什么它不起作用,我该如何解决?

编辑:我使用了chromebug而且找不到我的js ...我把它放在正确的路径上了吗?

以下是我的文件:

enter image description here

这是我的chromebug,我不知道这是什么意思.. :(:

enter image description here

3 个答案:

答案 0 :(得分:2)

您忘记导入插件的.js文件。根据{{​​3}},您还应添加以下行:

<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

(并确保您的webapp也可以使用这些文件,即他们不会返回404)

答案 1 :(得分:2)

这已经晚了几个月,但似乎错误发生了,因为验证引擎需要jQuery 1.6+。它在https://github.com/posabsolute/jQuery-Validation-Engine上的经验法则部分中说明。 “从2.2.4开始,由于prop(),需要jquery 1.6+”。希望这会有所帮助。

答案 2 :(得分:1)

您拥有的一个好处是javascript(jquery)对JSP / ASP / PHP或任何其他服务器端技术一无所知。所以你可以从输出的html中取出它并从那里开始排除故障。

乍一看,我没有看到添加的javascript验证插件。它现在是核心的一部分吗?