<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<div id='div1' style="height:100px; width:100px; background-color:#006600" οnclick='gg("test")'></div><input value="add" type="button" onClick="a()"><input value="remove" type="button" onClick="b()">
<div id='div2' style="height:100px; width:100px; background-color:#006600" ></div>
<SCRIPT LANGUAGE="JavaScript">
function $(Id){return document.getElementById(Id)}
function gg(b){alert(b)}
function addListener(element,e,fn){ element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn)}
function removeListener(element,e,fn){ element.removeEventListener?element.removeEventListener(e,fn,false):element.detachEvent("on" + e,fn)}
function a(){addListener($('div2'),'click',function (){gg('abc')})}
function b(){
removeListener($('div2'),'click',gg)
removeListener($('div1'),'click',function (){gg('test')})
}
</SCRIPT>
</body>
</html>
动态绑定javascript函数的共用方法
最新推荐文章于 2024-01-15 13:57:28 发布