Long form using jquery Validate causes IE slowscript warning

前端 未结 3 1440
礼貌的吻别
礼貌的吻别 2021-01-06 05:58

I have been using jquery validate plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation/. It has been working successfully, though now I have a form with a ta

3条回答
  •  無奈伤痛
    2021-01-06 06:47

    We recently had similar issue with a page containing more than 600 checkboxes. The solution we found was to redefine the "elements" function of jquery validate. This methods (as we understand it) seems to be in charge of detecting all inputs of the form. This list of inputs is then used to call the valid() method for each input name. Given the sheer amount of checkboxes this causes a huge overhead (each input resulting in a jquery object being created).

    The elements method was reimplemented as follow:

    var ret=[];
    var form=$(this.currentForm);
    for(var inputName in this.settings.rules){
        var inputs=form.find("[name='"+inputName+"']");
        if(inputs.length>0){
            console.log("Found input name: "+inputName);
            ret.push(inputs[0]);
        }
     }
     return ret;
    

    In our case we went from several 100ms with the original elements method to ~10ms with Firefox.

    Note Jquery validate version 1.11.1

提交回复
热议问题