Skip to content

Instantly share code, notes, and snippets.

@simplelife7
Created May 20, 2012 08:57
Show Gist options
  • Select an option

  • Save simplelife7/2757417 to your computer and use it in GitHub Desktop.

Select an option

Save simplelife7/2757417 to your computer and use it in GitHub Desktop.
【JS】在外层元素监听事件
// 使用事件代理,在更外层的元素上监听事件
document.getElementById('list').onclick = function(evt){
var evt = evt || window.event,
target = evt.target || evt.srcElement;
if(target.id === 'btn1'){
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment