var EventUtil = new Object;
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
if (oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
} else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
} else {
oTarget["on" + sEventType] = fnHandler;
}
};
function handleOnblur(div) {
alert(div.id);
}
var o = function(){
var oDiv = document.getElementById("div1");
handleOnblur(oDiv);
}
window.onload = function() {
var oDiv = document.getElementById("div1");
EventUtil.addEventHandler(oDiv, "blur", o);
}
可以使用上面这种方式,也可以使用prototype 方式。
function handleOnblur() {
alert(handleOnblur.prototype.addObject);
}
var oDiv = document.getElementById("div1");
handleOnblur.prototype.addObject = oDiv;