简单的事件处理

var oldColor;
var oldSize;
function clickDiv(obj){
alert(event);
obj.style.color = '#foo';
obj.style.fontSize = '22px';
    /*
    obj.style表示设置obj这个对象的style属性。
    obj.id表示设置id
    style.color表示设置css中的属性。特别注意,font-size,
    text-decoration等有中划线的属性,设置需要驼峰标识:
    fontSize,textDecoration
    */
}

function mouseover(obj){
    oldcolor = obj.style.color;
    /*在css中使用font-Size来设置字体大小,通过js需要
    使用驼峰标识(其它都类似);
    */
    oldSize = obj.style.fontSize;
    obj.style.color = '#foo';
    obj.style.fontSize = '22px';
}
function mouseout(obj){
    obj.style.color = oldColor;
    obj.style.fontSize = oldSize;
}

<body>
  <div onclick = 'clickDiv(this)' >点一下</div>
  <div onmouseover = "mouseover(this)" onmouseout = "mouseout(this)">移动</div>
</body>

原文地址:https://www.cnblogs.com/leole/p/4157159.html