简单的示例 div的背景色 会随着鼠标进入变红 离开变白 点击 变绿 双击变蓝
var divs = document.getElementsById('div1');
divs.onmouseover = function(){
this.style.background = 'red'
}
divs.onmouseout = function(){
this.style.background = ''
}
divs.onclick = function(){
this.style.background = 'green'
}divs.ondblclick = function(){
this.style.background = 'blue'
}
代码要写在 window.onload () 或者 document.onready()