使用 DOM 和事件來提供一些視覺效果
阿新 • • 發佈:2018-03-30
鼠標移出 程序 out why can brush 顏色 color 視覺效果
code:
<html> <head> <title>Introduction to the DOM</title> <script> //直到文檔完全載入,我們才能操作 DOM window.onload = function(){ //查找所有的<li>元素,附以事件處理程序 var li = document.getElementsByTagName("li"); for ( var i = 0; i < li.length; i++ ) { //將鼠標移入事件處理程序附在<li>元素上, //該程序改變<li>背景顏色為藍色 li[i].onmouseover = function() { this.style.backgroundColor = ‘blue‘; }; //將鼠標移出事件處理程序附在<li>元素上, //該程序將<li>的背景顏色改回白色 li[i].onmouseout = function() { this.style.backgroundColor = ‘white‘; }; } }; </script> </head> <body> <h1>Introduction to the DOM</h1> <p class="test">There are a number of reasons why the DOM is awesome, here are some:</p> <ul> <li id="everywhere">It can be found everywhere.</li> <li class="test">It‘s easy to use.</li> <li class="test">It can help you to find what you want, really quickly.</li> </ul> </body> </html>
使用 DOM 和事件來提供一些視覺效果