【问题标题】:jquery Plugins/Validation using submitHandler使用 submitHandler 的 jquery 插件/验证
【发布时间】:2010-04-10 17:42:23
【问题描述】:

问候,

我正在使用 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));

                  }



            });

【问题讨论】:

    标签: asp.net jquery


    【解决方案1】:

    要启用调试提交,我需要在规则的验证功能中通过添加以下行将调试设置为 true:debug: 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));
    
                  }
    
    
    
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 2020-11-08
      相关资源
      最近更新 更多