绊倒在JavaScript dom元素计数器计数器在这里和在这里(由lingtalfi提供)加快我的网站。显然,DOM元素的长度和深度似乎具有 on speed 。我想计算DOM开销,并在HTML中显示它,而无需键盘。这可以在页面加载以不干扰网站的速度后进行5秒钟。
方法1:警报弹出框
<a href="
javascript: (function()
{alert(document.getElementsByTagName('*').length);
}());
">Count DOM nodes of a page
</a>
方法2:只需在我的网站上的HTML写入
<script>
(function() {
document.write(document.getElementsByTagName('*').length);
}());
</script>
第一个方法弹出814,而第二种方法则写入142。
我的问题是:有没有办法(延迟和)在HTML中输出正确数量的DOM元素数,而无需单击弹出窗口以计算DOM元素?
(function () {document.write(document.getElementsByTagName('*').length); }());
body {
font-size: 5em;
font-family: "Arial";
}
Stumbling upon a Javascript DOM Elements Counter here and here (courtesy of lingtalfi) I want to speed up my website. Apparently the number of, the length of and the depth of DOM elements seems to have an impact on speed. I want to count the DOM overhead and show it in the HTML without a need for a keypress. This could be done 5 seconds after the page has loaded to not interfere with the speed of the website.
Method 1: Alert Popup Box
<a href="
javascript: (function()
{alert(document.getElementsByTagName('*').length);
}());
">Count DOM nodes of a page
</a>
Method 2: Just Write in HTML
<script>
(function() {
document.write(document.getElementsByTagName('*').length);
}());
</script>
On my site the first method popups 814, while the second method writes 142. Quite a difference!
My question is: Is there a way to (delay and) output the correct number of DOM elements just in HTML without the need to click on a popup to count the DOM elements?
(function () {document.write(document.getElementsByTagName('*').length); }());
body {
font-size: 5em;
font-family: "Arial";
}
发布评论
评论(1)
我绝对不确定您的问题!
您在寻找类似的东西吗?
请记住,演示中的数字可能比代码显示的大。堆栈溢出在场景后面增加了更多元素。
I am absolutely not sure about your question!
Are you searching for something like that ?
Please keep in mind that the number in the demo may be larger than the code shows. Stack Overflow adds more elements behind the scenes.