<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<input type="button" value="按钮" id="btn"/>
<script src="common.js"></script>
<script>
//为任意元素.绑定任意的事件, 任意的元素,事件的类型,事件处理函数
function addEventListener(element,type,fn) {
//判断浏览器是否支持这个方法
if(element.addEventListener){
element.addEventListener(type,fn,false);
}else if(element.attachEvent){
element.attachEvent("on"+type,fn);
}else{
element["on"+type]=fn;
}
}
addEventListener(my$("btn"),"click",function () {
console.log("哦1");
});
addEventListener(my$("btn"),"click",function () {
console.log("哦2");
});
addEventListener(my$("btn"),"click",function () {
console.log("哦3");
});
// my$("btn")["on"+"click"]=function () {
//
// };
// function Person(name) {
// this.name=name;
// this.sayHi=function () {
// console.log("您好啊");
// };
// }
// var per=new Person("小明");
// if(per.sayHii){//判断这个对象中有没有这个方法
// per.sayHii();
// }else{
// console.log("没有这个方法");
// }
</script>
</body>
</html>