Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用submitHandler的jquery插件/验证_Asp.net_Jquery - Fatal编程技术网

Asp.net 使用submitHandler的jquery插件/验证

Asp.net 使用submitHandler的jquery插件/验证,asp.net,jquery,Asp.net,Jquery,问候, 我正在使用jquery插件/验证库。我想允许提交时进行验证,但我不确定应该在何处插入代码: 我知道我可以使用submitHandler,但是在阅读了文档之后,我很难实现它,所以我需要你们的帮助 jquery验证工作正常,但问题是即使存在无效输入,表单仍然提交 这是我的验证函数,我想知道如果有无效输入,我如何使它不提交表单 顺便说一下,我正在使用asp.net按钮提交表单 这是我的密码: $(document).ready(function() { $("

问候,

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

                  }



            });

要启用debugon submit,我需要在规则的validate函数中将debug设置为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));

              }



        });