1

Well i notice a performance problem in chrome, if i do:

console.time('someFunction timer');

//one of both

//document.getElementById("R_"+row+"_C_"+(col+1)+"_D_"+day).focus();
document.getElementById("R_"+row+"_C_"+(col+1)+"_D_"+day).select();
console.timeEnd('someFunction timer');

Time is about: 150ms in chrome and only 15ms in firefox. Is any problem with focus() method or select() method in chrome?

If i use jQuery times are similar like:

console.time('someFunction timer');

//one of both

//$("#R_"+row+"_C_"+(col+1)+"_D_"+day).focus();
$("#R_"+row+"_C_"+(col+1)+"_D_"+day).select();
console.timeEnd('someFunction timer');

SOLVED Temporary:

Well i found a temporary solution, problem is in Chrome, when work with many (thousands) of input text, goes slowly. Solution for me is remove form tags, and then when i click in submit button, catch it with jQuery and create a new form, and append to body and then submit this new form with only changed inputs.

             for (var z=1;z<=48;z++){
                 var select = $("#R_"+i+"_C_"+z+"_D_"+day);
                 bodyform += '<input type="text" name="ID_'+select.data("idp")+'_C_'+select.data("coll")+'_D_'+day+'_H_'+z+'" value="'+select.val()+'"/>';
            }

            $("#plantables").append('<form id="myForm" style="margin: 0px;" action="{{ path(app.request.attributes.get('_route') , {'shop':app.request.get('shop'),'iduniverse': universe.iduniverso}) }}" method="post">'+bodyform+'</form>');
            //$("#plantables").after('</form>');
            $("#myForm").submit();

Another trick is to delete name property of input, i see that decrease speed if exists, but then problem is when you need to send form, this inputs doens´t attach to post, but if named just before send you solve it.

Same thing with id property.

Firefox or IExplorer works fine with forms and inputs.

4

1 回答 1

0

focus() 是一个 dom API。它负责重排元素。它重新计算元素的位置并阻止浏览器执行任何其他操作。很少有方法负责回流。你可以在这里查看: https ://gist.github.com/paulirish/5d52fb081b3570c81e3a

于 2020-03-25T10:46:32.500 回答