在Javascript / jQuery中(e)是什么意思? [英] In Javascript/jQuery what does (e) mean?

查看:110
本文介绍了在Javascript / jQuery中(e)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JavaScript / jQuery的新手,我一直在学习如何制作功能。 (e)括号中出现了很多函数。让我告诉你我的意思:

  $(this).click(function(e){
//做一些
});

它总是显示函数甚至不使用(e)的值,所以为什么它经常出现吗?

解决方案

事件将传递给事件处理程序的对象。



事件对象本质上有很多有趣的方法和属性可以用在事件处理程序中。



在您发布的示例中,它是一个点击处理程序,它是 MouseEvent



$ $ $ $ $ $(< ; //会返回你点击
}

DEMO - 鼠标事件DEMO使用 e.which e.type



一些有用的参考资料:

http://api.jquery.com/category/events/



http://www.quirksmode.org/js/events_properties .html



http: //www.javascriptkit.com/jsref/event.shtml




$ b

http://www.w3.org/TR/DOM-Level-3-Events/#event-类型列表


I am new to JavaScript/jQuery and I've been learning how to make functions. A lot of functions have cropped up with (e) in brackets. Let me show you what I mean:

$(this).click(function(e) {
    // does something
});

It always appears that the function doesn't even use the value of (e), so why is it there so often?

解决方案

e is the short var reference for event object which will be passed to event handlers.

The event object essentially has lot of interesting methods and properties that can be used in the event handlers.

In the example you have posted is a click handler which is a MouseEvent

$(<element selector>).click(function(e) {
    // does something
    alert(e.type); //will return you click
}

DEMO - Mouse Events DEMO uses e.which and e.type

Some useful references:

http://api.jquery.com/category/events/

http://www.quirksmode.org/js/events_properties.html

http://www.javascriptkit.com/jsref/event.shtml

http://www.quirksmode.org/dom/events/index.html

http://www.w3.org/TR/DOM-Level-3-Events/#event-types-list

这篇关于在Javascript / jQuery中(e)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆