事件绑定:
ie兼容下:attachEvent(事件名,函数);
FF兼容下:addEventListener(事件名,函数,false);
<script>
window.οnlοad=function()
{
var oBtn1=document.getElementById('btn1');
/*oBtn1.οnclick=function()
{
alert('a');
}
oBtn1.οnclick=function()
{
alert('b');
}*/
//ie兼容绑定写法
oBtn1.attachEvent(onclick,function(){alert('a')});
oBtn1.attachEvent(onclick,function(){alert('b')});
//FF兼容绑定写法
oBtn1.addEventListener(click,function(){alert('a')},false);
oBtn1.addEventListener(click,function(){alert('b')},false);
//兼容性写法
if(oBtn1.attachEvent)
{
oBtn1.attachEvent(onclick,function(){alert('a')});
oBtn1.attachEvent(onclick,function(){alert('b')});
}
else
{
oBtn1.addEventListener(click,function(){alert('a')},false);
oBtn1.addEventListener(click,function(){alert('b')},false);
}
};
</script>
<body>
<input id="btn1" type="button" value="按钮"/>
</body>