日期:2014-05-16 浏览次数:20520 次
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
//绑定事件
function myAddEvent(obj ,sEvent ,fn)
{
//IE
if(obj.attachEvent)
{
obj.attachEvent('on'+sEvent, fn);
}
//其他浏览器
else if(obj.addEventListener)
{
obj.addEventListener(sEvent, fn, false); //这里添加false,表示不需要捕获
}
}
//解绑事件,不支持匿名函数
function myDeleEvent(obj ,sEvent, fn)
{
//IE
if(obj.detachEvent)
{
obj.detachEvent('on'+sEvent, fn);
}
//其他浏览器
else if(obj.removeEventListener)
{
obj.removeEventListener(sEvent, fn ,false);
}
}
var aaa=function()
{
alert('a');
}
var bbb=function()
{
alert('b');
}
window.onload=function ()
{
var obtn=document.getElementById('btn1');
myAddEvent(obtn, 'click',aaa); //添加
myAddEvent(obtn, 'click',bbb);
}
</script>
</head>
<body>
<input id="btn1" type="button" value="aaa" />
</body>
</html>