zoukankan      html  css  js  c++  java
  • 用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>
    
  • 相关阅读:
    【转】Foreach用法
    【转】PB实现在通知区域添加图标
    手动清理SQLSERVER的日志文件
    2012腾讯实习笔试
    触控(捕鱼达人)笔试
    C和指针第五章操作符和表达式
    浮点数的存储
    C和指针第三章数据
    动态规划
    有关海量数据处理
  • 原文地址:https://www.cnblogs.com/flying-tx/p/3795402.html
Copyright © 2011-2022 走看看