jquery验证未定义的'form',即8

时间:2014-01-27 12:10:48

标签: jquery internet-explorer-8 jquery-validate

      showErrors: function(errorMap, errorList){
          this.defaultShowErrors();
          if(errors != '') {               

            var errorStr = '<p>Please make the following updates before continuing:</p>';
            errorStr +='<ul>';
            var tempArray  = [];
            for(i=0; i<errorList.length; i++) {                  
              tempArray .push(errorList[i]['message']);            
               $(errorList[i]['element']).addClass("error");
             }


               errorStr +='</ul><p>When done, click <strong>Next</strong></p>';                 
               $("#js_error_info").show();
             $("#js_error_info").html(errorStr);
            // $("#js_error_info").focus();
             $('html,body').animate({scrollTop: $('#js_error_info').offset().top}, "slow");
          }else{
             form.submit();
          }

      },

此代码是用Jquery验证函数/方法编写的。 当代码调用form.submit()时,它会给我Javascript错误“'form'未定义”,而它在所有其他浏览器上工作。我的表单元素id是“frm_about_you_single”,如果我将使用$(“#frm_about_you_single”)调用。则提交()然后它会给出“Out of Memeory error”。

1 个答案:

答案 0 :(得分:0)

  • form回调函数中未定义showErrors参数,因此在任何兼容的浏览器中都可以使用它是莫名其妙的。

  • 您应该 NOT 从任何可选回调函数中调用.submit(),但submitHandler回调函数除外, if / when是否要覆盖默认行为,该行为已经是.submit()

  • 您的OP中缺少太多代码来提供完整的答案,但基本上,插件会自动为您处理所有内容...没有合理的理由将.submit()放入{{1}回调函数。此可选功能仅用于一件事:"A custom message display handler. Gets the map of errors as the first argument and an array of errors as the second, called in the context of the validator object."

  • showErrors仅在表单有效时触发。默认情况下,当您将其从submitHandler选项中删除时,只需在表单通过验证后将表单提交给常规.validate() <form>