문제

I am using Mootools and adding a click event to a link. I have added a function to an event with this:

$('addCallRoute').addEvent('click', addCallRoute); // Add button

The function contains this:

function addCallRoute(e) {
    console.log(e);
}

The function that fires the event (without an actual click)

$('addCallRoute').fireEvent('click');

The Problem: When I click on the link physically, e is defined. but when I programmatically fire the event, e is undefined. Why?

도움이 되었습니까?

해결책

Because you're not actually/physically triggering an action but firing it remotely. This is how it works.

event normally contains all sort of information about the element from which the action was triggered.

Always check if event is defined before trying to use any methods on it. Or do this:

link.fireEvent('click', {
    stop: function(){}
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top