如何将事件对象传递给命名函数
问题描述:
我有一个click事件的事件处理程序。事件处理程序是命名函数而不是匿名函数。如何将事件对象传递给此命名函数?
I have an event handler for the click event. The event handler is a named function instead of an anonymous function. How can I pass the event object to this named function?
// usual example
$(".sel").click(function(ev) {
// do stuff which involves the event
});
// my case
$(".sel").click(myHandler);
function myHandler() {
// hopefully do stuff which involves the event
}
答
默认情况下,事件作为参数传递给事件处理函数
function myHandler(evt) {
// You can use event object here
}