javascript改变背景/字体颜色(Through the javascript to change the background and font color)

时间:2023-03-08 16:58:18

鼠标移动到、移出DIV时修改DIV的颜色:

1.Change the font and Div background color--function

<div style="width:200px;height:200px;border:1px solid #ccc;color:#555" onmouseover="size()" onmouseout="size1()" id="d1">     sajdaskjdaslkj </div>
<script language="javascript">
function size(){
document.getElementById("d1").style.color = "red"/*修改字体颜色*/
document.getElementById("d1").style.backgroundColor = "red"/*修改背景颜色*/   
}
function size1(){
document.getElementById("d1").style.color = "#888"/*修改字体颜色*/   
document.getElementById("d1").style.backgroundColor = "red"/*修改背景颜色*/  
}
</script>

2.Change the font and Div background color

<DIV style="BACKGROUND-COLOR: #fcc" id=leftOuthosRecord class=labeldiv onmouseover="javascript:this.style.backgroundColor='blue';" onmouseout="javascript:this.style.backgroundColor='#CCC'"  onclick="HiddendivContent('#rightOuthosRecord','#leftOuthosRecord','#CCC')">TEST</DIV>