<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Bing search</title></head><body><h1 id="a">你好</h1><script>// getElementById,通过id获取元素var getDom = function (id){return document.getElementById(id);};// 给元素绑定事件var addEvent = function(id,event,fn){var el = getDom(id)||document;//非IE浏览器if(el.addEventListener){el.addEventListener(event,fn)}else if(el.attachEvent){el.attachEvent('on'+event,fn);}};</script></body></html>浏览器是360的,getDom是可用的;getDom('a')<h1 id="a">你好</h1>addEvent('a','click',function(){alert(5)})undefined
添加回答
举报
0/150
提交
取消