猿问

跨平台兼容性,不知道哪里出错了

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Insert title here</title>

<script type="text/javascript">

function showmes(){

alert("跨平台事件处理");

}

var but3=document.getElement("but3");

  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.detachEvent){

element.detachEvent('on'+type,handler);

}else{

element['on'+type]=null;

}

}

}

eventutil.addHandler(but3,'click',showmes);


</script>

</head>

<body>

<input type="button" value="按钮3" id="but3">

</body>

</html>


qq_原地等一个人_0
浏览 1376回答 1
1回答

Amumu

最好说明一下什么问题
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答