{"action":"opened","issue":{"url":"https://api.github.com/repos/jennyWan278/issue/issues/45","repository_url":"https://api.github.com/repos/jennyWan278/issue","labels_url":"https://api.github.com/repos/jennyWan278/issue/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/jennyWan278/issue/issues/45/comments","events_url":"https://api.github.com/repos/jennyWan278/issue/issues/45/events","html_url":"https://github.com/jennyWan278/issue/issues/45","id":360651903,"node_id":"MDU6SXNzdWUzNjA2NTE5MDM=","number":45,"title":"事件","user":{"login":"jennyWan278","id":29098309,"node_id":"MDQ6VXNlcjI5MDk4MzA5","avatar_url":"https://avatars0.githubusercontent.com/u/29098309?v=4","gravatar_id":"","url":"https://api.github.com/users/jennyWan278","html_url":"https://github.com/jennyWan278","followers_url":"https://api.github.com/users/jennyWan278/followers","following_url":"https://api.github.com/users/jennyWan278/following{/other_user}","gists_url":"https://api.github.com/users/jennyWan278/gists{/gist_id}","starred_url":"https://api.github.com/users/jennyWan278/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennyWan278/subscriptions","organizations_url":"https://api.github.com/users/jennyWan278/orgs","repos_url":"https://api.github.com/users/jennyWan278/repos","events_url":"https://api.github.com/users/jennyWan278/events{/privacy}","received_events_url":"https://api.github.com/users/jennyWan278/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-16T15:52:49Z","updated_at":"2018-09-16T15:52:49Z","closed_at":null,"author_association":"OWNER","body":"事件处理程序：\r\n* HTML事件处理程序\r\n```javascript\r\n<input type = \"button\" value = \"click me\" onclick =  \"showMessage()\" />\r\n\r\n<script>\r\n  function showMessage() {\r\n     alert(\"hello word\"); \r\n  }\r\n</script> \r\n```\r\n```javascript\r\n<input type = \"button\" value = \"click me\" onclick =  \"event.type\" />\r\n\r\n// this等于事件的目标元素\r\n<input type = \"button\" value = \"click me\" onclick =  \"this.value\" />\r\n```\r\n* DOM0级 事件处理程序\r\n```javascript\r\n<input id = \"myBtn\" type = \"button\" value = \"click me\" onclick =  \"showMessage()\" />\r\n\r\n<script>\r\nvar btn = document.getElementById(\"myBtn\");\r\nbtn.onclick = function (){\r\n    alert (this.id)\r\n}\r\n\r\n// 清除\r\nbtn.click = null;\r\n</script> \r\n```\r\n* DOM2级 事件处理程序(ie9)\r\n```javascript\r\n<input id = \"myBtn\" type = \"button\" value = \"click me\" onclick =  \"showMessage()\" />\r\n\r\n<script>\r\nvar btn = document.getElementById(\"myBtn\");\r\n// 第三个参数：为true时：表示在捕获阶段调用事件处理程序\r\n                       ：为false时：表示在冒泡阶段调用事件处理程序\r\nbtn.addEventLister(”click“ , function(){\r\n    alert(\"hello word\");\r\n},false);\r\n// 可以添加多个事件处理程序\r\nbtn.addEventLister(”click“ , function(){\r\n    alert(\"hello word\");\r\n},false); \r\n// 清除\r\n// 使用removeEventLister(),移除时传入的参数与添加事件处理程序时使用的参数相同\r\nvar hander = function () {\r\n   alert(this.id);\r\n};\r\n btn.addEventLister(\"click\", handler, false);\r\nbtn.removeEventLister(\"click\", handler, false);\r\n\r\n</script> \r\n```\r\n* IE事件处理程序(ie8 ie8-)\r\n```javascript\r\n<input id = \"myBtn\" type = \"button\" value = \"click me\" />\r\n\r\n<script>\r\nvar btn = document.getElementById(\"myBtn\");\r\n  btn.attachEvent(\"onclick\",function() {\r\n     alert(\"clicked\");\r\n    // 该方法在全局范围作用域中运行,\r\n    alert(this == window);   // true\r\n  })\r\n// 可以绑定多个事件，但是是以相反的顺序触发\r\n  btn.attachEvent(\"onclick\",function() {\r\n     alert(\"hello\");\r\n    // 该方法在全局范围作用域中运行,\r\n    alert(this == window);   // true\r\n  })\r\n</script> \r\n\r\n// 清除\r\nbtn,detachEvent(\"onclick\" handler);\r\n```\r\n* 跨浏览器的事件处理程序\r\n```javascript\r\n  var EventUtil ={\r\n      addHandler : function(element , type , handler) {\r\n           if(element.addEventLister) {\r\n                element.addEventLister(type,handler,false);\r\n           } else if (element.attachEvent) {\r\n                element.attachEvent(\"on\"+type,handler);\r\n              } else {\r\n                element[\"on\"+ type] = handler;\r\n              }\r\n      },\r\n      removeHandler : function(element , type , handler) {\r\n           if(element.removeEventLister) {\r\n                element.removeEventLister(type,handler,false);\r\n           } else if (element.detachEvent) {\r\n                element.detachEvent(\"on\"+type,handler);\r\n              } else {\r\n                element[\"on\"+ type] = null;\r\n              }\r\n      },\r\n  };\r\n```\r\n```javascript\r\n // 用法\r\nvar btn = document.getElemntById(\"myBtn\");\r\nvar handler = function () {\r\n    alert(\"clicked\");\r\n}\r\n\r\nEventUtil.addHandler(btn,\"click\",handler);              // 添加\r\nEventUtil.removeHandler(btn,\"click\",handler);        // 清除\r\n```\r\n"}}
{"actor":{"display_login":"jennyWan278"}}