Javascript事件的重载

  标题如此,却不知算不算是重载,只是觉得象而已,呵呵。
  在Javascript中,如果已经定义了一个document.onclick,而我后面再定义的时候,就会覆盖原来的过程。因此,在定义后一个document.onclick时必须对之前的过程进行引用执行。
  代码如下,很简单的:
document.onclick = function ()
{
  alert(
"this old function");
}

//new
if(document.onclick)
{
  
var events = 'this.oldEventHandler = ' + document.onclick.toString();
}

document.onclick 
= function()
{
  
if(events != undefined){eval(events);this.oldEventHandler();};
  
// do something
}
原文地址:https://www.cnblogs.com/faib/p/748076.html