Jquery验证不起作用

时间:2013-12-20 02:30:26

标签: jquery html jquery-validate

通常我已成功在My HTML上安装Jquery验证。现在停止,我混淆验证不能正常工作。

这是HTML脚本

 <table border="0" align="center">
           <form method="post" action="undian.php" id="FORM_UNDIAN">

          <tr> 
           <td>Nama :</td>
           <td><input type="text" name="NAMA" placeholder="Nama" class="inputs" /></td>
           </tr>
           <tr>
             <td>Email :</td>
             <td><input type="text" name="EMAIL" placeholder="Email" class="inputs" /></td>
           </tr>
           <tr>
             <td>Kota  :</td>
             <td>
             <div class="ui-widget">

                 <input type="text" name="KOTA" placeholder="Kota" id="tags" class="inputs" />
             </div><!--end of ui-widget-->

              </td>
           </tr>
           <tr>
             <td colspan="2" align="right"> <input type="submit" name="OKE" value="Submit" id="submit1" /></td>
          </tr>
          </table>

js脚本就像这样

<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-validate-1.10.0.js"></script>
<script>
    $(function(){
        $("#FORM_UNDIAN").validate({
            rules: 
               {
                 NAMA: 
                 {
                    required: true
                 },
                 EMAIL: 
                {
                    required: true,
                    email : true
                },
                 KOTA:
                 {
                   required: true
                 }

              },
            messages: {
                NAMA: 
                {
                    required: "Nama belum terisi"
                },
                EMAIL: 
                {
                    required: "Email  belum terisi",
                    email : "Format email belum benar"
                },

               KOTA:
               {
                   required: "Kota belum dipilih"
               }

            }
        })
    });
    </script>

你能帮我告诉我的剧本错误吗?

我非常感谢你的答案。

由于

1 个答案:

答案 0 :(得分:1)

您的html无效,table cannot have form as a child,因此请将表单设为表格的父级

<form method="post" action="undian.php" id="FORM_UNDIAN">
    <table border="0" align="center">
        <tr>
            <td>Nama :</td>
            <td>
                <input type="text" name="NAMA" placeholder="Nama" class="inputs" />
            </td>
        </tr>
        <tr>
            <td>Email :</td>
            <td>
                <input type="text" name="EMAIL" placeholder="Email" class="inputs" />
            </td>
        </tr>
        <tr>
            <td>Kota :</td>
            <td>
                <div class="ui-widget">
                    <input type="text" name="KOTA" placeholder="Kota" id="tags" class="inputs" />
                </div>
                <!--end of ui-widget-->
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right">
                <input type="submit" name="OKE" value="Submit" id="submit1" />
            </td>
        </tr>
    </table>
</form>

演示:Fiddle

查看your html输入元素不在表单元素