<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>跨浏览器支持</title>
<script type="text/javascript">
var btn=document.getElementById('btn');
function showMes() {
alert("hello world");
}
var EventUtill={
addHander:function (elment,type,hander) {
if (elment.addEventListener) {
elment.addEventListener(type,hander,false);
} else if(elment.attachEvent){
elment.attachEvent('on'+type,hander);
}else{
elment['on'+type]=hander;
}// body...
},
removeHander:function (elment,type,hander) {
if (elment.removeEventListener) {
elment.removeEventListener(type,hander,false);
} else if(elment.detachEvent){
elment.detachEvent('on'+type,hander);
}else{
elment['on'+type]=null;
}// body...
}
}
EventUtill.addHander(btn,'click',showMes);
</script>
</head>
<body>
<input type="button" id="btn" value="按钮">
</body>
</html>
Caballarii
相关分类