childNodes
数量的函数。 function countBodyChildren() {
var body_element = document.getElementsByTagName("body")[0];
alert(body_element.childNodes.length);
}
window.onload = countBodyChildren;
该函数可以正常运行,但是当我在函数名后面添加()
时,即window.onload = countBodyChildren();
,函数就不能正常运行了。为什么会这样呢?我认为调用函数时,即使它们不需要任何参数,也总是要在函数名后面加上()
。