2010-03-15 53 views
0

我有一個問題,使用jquery插件/驗證。實現jquery插件添加方法驗證

我想補充的方法和遵循的文檔,但我想我還是缺少一些東西。

首先我想補充的方法,但我想我要實現它的一個問題。

請檢查我的代碼,並建議我。

<script src="js/jquery-1.4.1.js" type="text/javascript"></script> 

    <script src="js/jquery.validate.js" type="text/javascript"></script> 


    <script type="text/javascript"> 



     $(document).ready(function() { 

     jQuery.validator.addMethod("domain", function(value, element) { 
      return this.optional(element) || /^http:\/\/yahoo.com/.test(value); 
     }, "Please specify the correct domain for your documents"); 



      $("#aspForm").validate(); 
     }); 

    <asp:TextBox ID="TextBox1" runat="server" CssClass="domain" ></asp:TextBox> 


</script> 
+0

你TextBox1的是在aspForm吧?這不是代碼就是這樣嗎? – JustinP8 2010-03-15 19:35:59

回答

0

我能找到如何實現驗證規則權代碼: 這裏是代碼:

<script src="js/jquery-1.4.1.js" type="text/javascript"></script> 

    <script src="js/jquery.validate.js" type="text/javascript"></script> 


    <script type="text/javascript"> 


    //Our validation script will go here. 
     $(document).ready(function() { 

      jQuery.validator.addMethod("domain", function(value, element) { 
      return this.optional(element) || /^http:\/\/yahoo.com/.test(value); 
     }, "Please specify the correct domain for your documents"); 





      //validation implementation will go here. 
      $("#aspnetForm").validate({ 
       rules: { 
        "<%=TextBox1.UniqueID %>": { 

         domain: true 
        } 
       } 

      }); 
     }) 

</script>