JavaScript 函数闭包实现多个事件的监听
function AddEvent(obj, evt, fn)
{
var saved;
if(typeof obj[“on" + evt] == " function")
{
saved = ojb["on" + evt];
}
obj["on" + evt] = function()
{
if(saved)
saved();
fn();
}
}
var functions =[];
function addEvent(obj , evt, fns)
{
functions.push(fn);
if(typeof obj ["on" + evt] == "function")
{
functions.push(obj["on" + evt]);
}
obj["on" + evt] = function()
{
for(var i = 0; i< functions.length; i++)
{
functions[i].call(this);
}
}
}