表格隔行变色以及鼠标移上变色 js代码

var oldColor='';
				//var oTab=document.getElementById('tab1')
		function toColor(tableID)
		{
			    var oTab=document.getElementById(tableID)
				
			   	for(var i=0;i<oTab.tBodies[0].rows.length;i++)
			   //隔行变色
			   {    
			   	    oTab.tBodies[0].rows[i].onmouseover=function()
			   	    {  //鼠标移入变色
						
			   	    	oldColor=this.style.background;
			   	    	this.style.background='#dff0d8';
			   	    };
			   	    oTab.tBodies[0].rows[i].onmouseout=function()
			   	    {   //鼠标移出恢复原来颜色
			   	    	this.style.background=oldColor;
			   	    }
			   }
		}
toColor(tableId);

猜你喜欢

转载自blog.csdn.net/qq_40216244/article/details/82384177
今日推荐