最近我一直在做很多模态窗口弹出窗口,而不是,我使用了jQuery。 我用来在页面上创建新元素的方法绝对是:
$("<div></div>");但是,我觉得这不是最好的或最有效的方法。 从性能角度来看,在jQuery中创建元素的最佳方式是什么?
这个答案有以下建议的基准。
Recently I've been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of:
$("<div></div>");However, I'm getting the feeling that this isn't the best or the most efficient method of doing this. What is the best way to create elements in jQuery from a performance perspective?
This answer has the benchmarks to the suggestions below.
最满意答案
我使用$(document.createElement('div')); 基准测试表明这种技术是最快的。 我推测这是因为jQuery不必将其标识为元素并创建元素本身。
您应该使用不同的JavaScript引擎来运行基准测试,并根据结果衡量您的受众。 从那里作出决定。
I use $(document.createElement('div')); Benchmarking shows this technique is the fastest. I speculate this is because jQuery doesn't have to identify it as an element and create the element itself.
You should really run benchmarks with different Javascript engines and weigh your audience with the results. Make a decision from there.
更多推荐
发布评论