首页 > 代码库 > 用addOnload()函数设置多重onload属性

用addOnload()函数设置多重onload属性

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>用addOnload()函数设置多重onload属性</title><script>addOnload(initOne);addOnload(initTwo);addOnload(initThree);function addOnload(newFunction){	var oldOnload=window.onload;	if(typeof oldOnload == "function")	{			    window.onload = function(){		    if(oldOnload){				oldOnload();				}			newFunction();			}	}else{		window.onload = newFunction;	}}function initOne(){	document.getElementById(‘pagebody‘).style.backgroundColor =	 "#00F";}function initTwo(){	document.getElementById(‘pagebody‘).style.color = "#F00";}function initThree(){	var allTags = document.getElementsByTagName(‘*‘);		for(var i = 0;i < allTags.length;i++){		if(allTags[i].nodeName == ‘H1‘){		    allTags[i].style.border = ‘5px green solid‘;			allTags[i].style.padding = "25px";			allTags[‘i‘].style.backgroundColor = "#FFF";		}	}}</script></head><body id="pagebody">	<h1>Welcome to our school</h1></body></html>