<!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
qq_预_1
相关分类