当元素具有事件处理程序时,事件对象将传递给事件处理程序。除其他外,此事件对象还具有对触发事件的节点的引用。
所以…
var createSibling = function(_event){
var e = this; // the element this function is actually attached to
var event_e = _event.target; //another way to get at the element clicked
// do stuff
};
document.getElementById('myElement').onClick = createSibling;
document.getElementById('myElement').captureEvents(Event.CLICK);
问题是不同事物的属性名称不同,跨浏览器-这是另一种使用框架的方法,因为它们将实现浏览器检测和特定的实现,如果不使用的话,您需要这样做。
有关一些高级详细信息,请参见quirksmode.org:
http://www.quirksmode.org/js/introevents.html