Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to bind a function to the mouseout event of my <canvas> element, and bind the same function to the blur and contextmenu events of my body. How would I go about binding this function to those elements at once, when there are different elements which need the same function bound to different events of each?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
263 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can't. Define your function beforehand:

function eventHandler(event) {}

and assign it separately:

$('canvas').mouseout(eventHandler);
$('body').bind('blur contextmenu', eventHandler);

With .bind you can at least bind one event handler to multiple events.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...