<body>
<input type="button" value="按钮" id="btn" onclick="showMessage()"/>
<input type="button" value="按钮2" id="btn2" />
<input type="button" value="按钮3" id="btn3" />
<script>
function showMessage(){
alert('hallo world');
}
var btn2=document.getElementById('btn2');
var btn3=document.getElementById('btn3');
var eventUtil={
addHandler:function(element,type,handler)
{
if(element.addEventListener)
{elemnet.addEventListener(type,handler,false);}
else if(element.attachEvent)
{element.attachEvent('on'+type,handler);}
else{element['on'+type]=handler;}
}
removeHandler:function(element,type,handler)
{
if(element.removeEventListener)
{elemnet.removeEventListener(type,handler,false);}
else if(element.detachEvent)
{element.detachEvent('on'+type,handler);}
else{element['on'+type]=null;}
}
}
eventUtil.addHandler(btn3,'click',showMessage);
</script>
</body>
六道骸
相关分类