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>