方式一:
<p id='oo'>ddddddddddddddddddddddddddddddd</p>
<script>
var handler=function(e){
switch(e.type){
case "click":
alert('clicked');
break;
case "mouseover":
e.target.style.color='pink';
break;
case "mouseout":
e.target.style.color=""
}
};
var x=document.getElementById("oo");
x.onclick=handler;
x.onmouseover=handler;
x.onmouseout=handler;
</script>
方式二:
<p id='oo'>ddddddddddddddddddddddddddddddd</p>
<script>
var x=document.getElementById("oo");
x.addEventListener('click',function(e){
alert('ckicked');
});
x.addEventListener('mouseover',function(e){
e.target.style.color="pink"
});
x.addEventListener('mouseout',function(e){
e.target.style.color=""
});
</script>