<!DOCTYPE html>
<html>
<head>
<title>index</title>
</head>
<body>
<input type="button" id="btn1" value="按钮一">
<script type="text/javascript">
var btn1 = document.getElementById('btn1');
function message() {
alert("Hello World!");
}
var eventUtil = {
//添加句柄
addHandler:function(element, type, handLer){
if (element.addEventListener) {
element.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) {
element.removeEventListener(type, handLer, false);
} else if (element.attachEvent) {
element.detachEvent('on' + type, handLer);
} else {
element["on"+type] = null;
}
}
}
eventUtil.addHandler(btn1, "click", message);
</script>
</body>
</html> 找了半天都不知道哪里出问题了,运行不了,请大家帮忙看看,谢谢了~
添加回答
举报
0/150
提交
取消