How to attach a listener to an object that takes parameters and returns a value in JavaScript?
I can see how to attach an event to an object that has no parameters and no return value but how to modify the code below to attach a listener that takes parameters and returns a value?
function attachEventListener(target, eventType, functionRef,
capture)
{
if (typeof target.addEventListener != "undefined")
{
target.addEventListener(eventType, functionRef, capture);
}
else if (typeof target.attachEvent != "undefined")
{
target.attachEvent("on" + eventType, functionRef);
}
attachEventListener(mylink, "click", ClickMe, false);
I get no error when I do this but it also doesn't fire the event when the link is clicked eithier, Note my fu开发者_运维百科nctionRef is in this form Test(true, "Hello!"):
target.attachEvent("on" + eventType, function() {functionRef});
Thanks!
attachEventListener(myLink, 'click', function(foo, bar) { alert('yay! ' + foo); }, false);
精彩评论