您的位置:首页 > 其它

事件绑定

2015-06-10 11:50 274 查看
addEventListener() and removeEventListener();

These methods exist on all DOM nodes and accept three arguments: the event name to handle, the event handler function, and a Boolean value indicating whether to call the event handler during the capture phase (true) or during the bubble phase (false);

to add an event handler for the click event on a button, you can use the following code:

var btn = document.getElementById("myBtn");
btn.addEventListener("click", function() {
alert(this.id);
}, false)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: