js實現滑鼠移動到div背景顏色變換,移開還原
阿新 • • 發佈:2018-11-10
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js重溫</title> </head> <div id="sss" onmouseover = "over()" onmouseout="out()" style="width:100px;height:100px;color:red;background-color: green;color:red">滑鼠不 在上面 </div> </body> <script> function over(){ var x = document.getElementById("sss").innerHTML="滑鼠在上面的樣子"; var x = document.getElementById("sss").style.color="pink"; var x = document.getElementById("sss").style.backgroundColor="dodgerblue"; } function out(){ var x = document.getElementById("sss").innerHTML="滑鼠不在上面"; var x = document.getElementById("sss").style.color="red"; var x = document.getElementById("sss").style.backgroundColor="green"; } </script> </html>