给出这个代码,你如何检查文档中点击了哪个项目?
if ( document.addEventListener && document.attachEvent && document.fireEvent ) { document.attachEvent( "onclick",function() { // ... }); }
解决方法
// using e.srcElement or event.srcElement
尝试这个 :)
看到这个http://www.quirksmode.org/js/events_advanced.html
if (document.addEventListener ){ document.addEventListener("click",function(event){ var targetElement = event.target || event.srcElement; console.log(targetElement); }); } else if (document.attachEvent) { document.attachEvent("onclick",function(){ var targetElement = event.target || event.srcElement; console.log(targetElement); }); }