jquery验证不工作 [英] Jquery Validation Not Workng

查看:90
本文介绍了jquery验证不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我已经成功地在我的HTML上安装了Jquery验证。现在,我对验证工作感到不满。



这是HTML脚本

 < table border =0align =center> 
< form method =postaction =undian.phpid =FORM_UNDIAN>

< tr>
< td> Nama:< / td>
< td>< input type =textname =NAMAplaceholder =Namaclass =inputs/>< / td>
< / tr>
< tr>
< td>电子邮件:< / td>
< td>< input type =textname =EMAILplaceholder =Emailclass =inputs/>< / td>
< / tr>
< tr>
< td> Kota:< / td>
< td>
< div class =ui-widget>

< input type =textname =KOTAplaceholder =Kotaid =tagsclass =inputs/>
< / div><! - ui-widget的结尾 - >

< / td>
< / tr>
< tr>
< td colspan =2align =right> < input type =submitname =OKEvalue =Submitid =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>
$(函数(){
$(#FORM_UNDIAN)。validate({
规则:
{
NAMA:
{
必填:true
},
EMAIL:
{
required:true,
email:true
},
KOTA:
{
required:true
}

},
消息:{
NAMA:
{
required: Nama belum terisi

电子邮件:
{
所需:电子邮件地址,
电子邮件地址:格式电子邮件贝伦贝纳尔
} ,

KOTA:
{
所需:Kota belum dipilih
}

}
})
});
< / script>

你能帮我说出脚本上的错误吗?



我非常感谢您的答复。



谢谢

解决方案

你的html无效,表不能有表格作为孩子,因此请将表格作为表格的父母

 < form method =postaction = undian.phpid =FORM_UNDIAN> 
< table border =0align =center>
< tr>
< td> Nama:< / td>
< td>
< input type =textname =NAMAplaceholder =Namaclass =inputs/>
< / td>
< / tr>
< tr>
< td>电子邮件:< / td>
< td>
< input type =textname =EMAILplaceholder =Emailclass =inputs/>
< / td>
< / tr>
< tr>
< td> Kota:< / td>
< td>
< div class =ui-widget>
< input type =textname =KOTAplaceholder =Kotaid =tagsclass =inputs/>
< / div>
<! - ui-widget结束 - >
< / td>
< / tr>
< tr>
< td colspan =2align =right>
< input type =submitname =OKEvalue =Submitid =submit1/>
< / td>
< / tr>
< / table>
< / form>

演示:小提琴



看看您的html 输入元素不在表单元素


usually I've had success to install Jquery validation on My HTML. BUt now, I Confuses with validation that not working well.

This the HTML script

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

And the js script is like this

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

Can you help me to tell the mistake of on my script?

Im very appreciated your Answer.

Thanks

解决方案

Your html is invalid, table cannot have form as a child, so make the form as the parent of table

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

Demo: Fiddle

Look at your html the input elements are not within the form element

这篇关于jquery验证不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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