2010-04-10 81 views
0

問候語,jquery插件/驗證使用submitHandler

我正在使用jquery插件/驗證庫。我想允許驗證提交,但我不知道應該在哪裏插入代碼: 我知道我可以爲用戶submitHandler,但在閱讀文檔之後,我很難實現它,因此我需要您的幫助人員。

jquery驗證工作正常,但表單仍然提交的問題即使有無效的輸入。

這裏是我的驗證函數,我想知道如果無效輸入,我該如何使它不提交表單。

順便說一下,我使用asp.net按鈕來提交表單。

這裏是我的代碼:

$(document).ready(function() { 


      $("#aspnetForm").validate({ 




       rules: { 
        "<%=txtHomePhone.UniqueID %>": { 

         phonehome: true 
        }, 

        "<%=txtMobileHome.UniqueID %>": { 

         mobilephone: true 


       }, 

        "<%=txtFaxHome.UniqueID %>": { 

        faxhome: true 

       }, 

       "<%=txtEmailHome.UniqueID %>": { 

        email: true 

       }, 


       "<%=txtZipCodeHome.UniqueID %>": { 

       ziphome: true 

       }, 

       //work 
          "<%=txtPhonework.UniqueID %>": { 

         phonework: true 
        }, 

        "<%=txtMobileWork.UniqueID %>": { 

         mobilework: true 


       }, 

        "<%=txtFaxWork.UniqueID %>": { 

        faxwork: true 

        }, 
        "<%=txtEmailWork.UniqueID %>": { 

        email: true 

       }, 

       "<%=txtWebSite.UniqueID %>": { 

        url: true 

       }, 
       "<%=txtZipWork.UniqueID %>": { 

       zipwork: true 

       } 



       }, 




        errorElement: "mydiv", 
        wrapper: "mydiv", // a wrapper around the error message 

         errorPlacement: function(error, element) { 
         offset = element.offset(); 
         error.insertBefore(element) 
         error.addClass('message'); // add a class to the wrapper 
         error.css('position', 'absolute'); 
         error.css('left', offset.left + element.outerWidth()); 
         error.css('top', offset.top - (element.height()/2)); 

        } 



      }); 

回答

0

使debugon提交我需要調試在規則驗證功能設置爲true,加入這一行:調試:真實,

正確的代碼:

$(document).ready(function() { 


     $("#aspnetForm").validate({ 


       debug: true, 

      rules: { 
       "<%=txtHomePhone.UniqueID %>": { 

        phonehome: true 
       }, 

       "<%=txtMobileHome.UniqueID %>": { 

        mobilephone: true 


      }, 

       "<%=txtFaxHome.UniqueID %>": { 

       faxhome: true 

      }, 

      "<%=txtEmailHome.UniqueID %>": { 

       email: true 

      }, 


      "<%=txtZipCodeHome.UniqueID %>": { 

      ziphome: true 

      }, 

      //work 
         "<%=txtPhonework.UniqueID %>": { 

        phonework: true 
       }, 

       "<%=txtMobileWork.UniqueID %>": { 

        mobilework: true 


      }, 

       "<%=txtFaxWork.UniqueID %>": { 

       faxwork: true 

       }, 
       "<%=txtEmailWork.UniqueID %>": { 

       email: true 

      }, 

      "<%=txtWebSite.UniqueID %>": { 

       url: true 

      }, 
      "<%=txtZipWork.UniqueID %>": { 

      zipwork: true 

      } 



      }, 




       errorElement: "mydiv", 
       wrapper: "mydiv", // a wrapper around the error message 

        errorPlacement: function(error, element) { 
        offset = element.offset(); 
        error.insertBefore(element) 
        error.addClass('message'); // add a class to the wrapper 
        error.css('position', 'absolute'); 
        error.css('left', offset.left + element.outerWidth()); 
        error.css('top', offset.top - (element.height()/2)); 

       } 



     });