javascript
  • jquery
  • validation
  • input
  • 2012-07-18 65 views 8 likes 
    8

    JQuery验证仅适用于提交表单中的第一个元素,Validation不会检查第二个元素的 。需要找出缺少的东西。交换text1和date2的输入,验证仍然 适用于第一个。JQuery验证仅适用于提交表单中的第一个元素。 [打算验证所有]

    <!DOCTYPE HTML> 
    <html lang="en-US"> 
    <head><title> 
    </title> 
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.5.1.min.js'></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"></script> 
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"></script> 
    <script type="text/javascript" src="http://jquery-multifile-plugin.googlecode.com/svn-history/r16/trunk/jquery.MetaData.js"></script> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/base/jquery-ui.css"/> 
    
    <script type="text/javascript"> 
        $(document).ready(function() { 
         $("#form1").validate(); 
    
         $(".date").datepicker({ 
          changeYear: true, 
          dateFormat: 'dd/mm/yy', 
          minDate: new Date('1990/01/01'), 
          maxDate: '30Y' 
         }); 
        }); 
        function test() { 
         alert(document.getElementById("datetext").getAttribute("must")); 
        }   
    </script> 
    </head> 
    <body> 
         <form method="post" action="WebForm1.aspx" id="form1"> 
          Text:<font color="red">* </font><input id="Text1" class="lvl {required:true,messages:{required:'blank not allowed.'}}" /><br /> 
          Select Date2:<font color="red">* </font><input id="date2" class="date {required:true,messages:{required:'Required:Need to enter 2 date.'}}" readonly="true" /><br /> 
          <input type="submit" value="Submit"/> 
         </form> 
    </body> 
    </html> 
    

    回答

    27

    一定要包括name属性对您的输入。我相信它使用name属性来构建它的验证字段列表,并且由于您没有指定name属性,所以jquery验证认为第二个字段与第一个字段名称相同。

    例如,<input id="Text1" name="Text1" />

    +0

    谢谢,有这个问题,我们难住了,不知道为什么,虽然它不只是使用的元素,而不是名称字段。 – bigcakes 2013-05-03 18:57:08

    +0

    你不知道我是如何释放这个职位的。我一直在撞墙,试图弄清楚为什么我的验证程序无法正常工作,只突出显示第一个无效元素。官方的jQuery验证文档是废话,不知道这个问题很容易通过包含名称attr,lmao来解决。 – Nexus 2015-02-08 11:54:21

    +2

    我也失去了一些时间。请将此答案标记为已接受。 – Raffo 2015-03-21 10:24:45

    相关问题