关于window.onload=function的加载运行问题

HTML csshtml 发表于 9 月前

为什么把var headers=document.getElementsByTagName("h1"); var elem; for (var i=0;i<headers.length;i){ elem=getNextElement(headers[i].nextSibling); elem.style.fontSize="1.2em"; elem.style.fontWeight="bold"; }封装成函数之后,效果出不来?效果是h1下的第一个p加粗
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CSS-DOM</title>
</head>
<body>
<p id="p" style="color:blue">An example of a paragraph</p>
<h1>Hold the front page</h1>
<p>This first paragraph leads ypu in</p>
<p>Now you get the nitty-gritty of the story</p>
<p>Yhe most important information is delivered first.</p>
<h1>Hold the front page</h1>
<p>This first paragraph leads ypu in</p>
<p>Now you get the nitty-gritty of the story</p>
<p>Yhe most important information is delivered first.</p>
<script>
window.onload=function(){
function styleHeaderSiblings(){//加上之后不执行
var headers=document.getElementsByTagName("h1");
var elem;
for (var i=0;i<headers.length;i
){
elem=getNextElement(headers[i].nextSibling);
elem.style.fontSize="1.2em";
elem.style.fontWeight="bold";
}
}
function getNextElement(node){
if(node.nodeType==1){
return node;
};
if (node.nextSibling) {http://www.9ask.cn/xiamen/
return getNextElement(node.nextSibling);
};
return null;
}
}</script>
</body>
</html>

暂无回复,说出你的观点吧
登录后即可参与回复