活动 [英] Events

查看:48
本文介绍了活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我目前对我遇到的一段代码感到困惑:

Hi everyone
I am currently confused about a piece of code that I have encountered:

展开 | 选择 | Wrap | 行号

推荐答案

disappearedng meinte:
disappearedng meinte:

大家好

我目前对一件事感到困惑我遇到的代码:

Hi everyone
I am currently confused about a piece of code that I have encountered:

展开 | 选择 | Wrap | 行号


Gregor Kofler写道:
Gregor Kofler wrote:

disappearedng meinte:
disappearedng meinte:

>我目前对我遇到的一段代码感到困惑:

[code]
function handleKeyUp(e){

e = (!e)? window.event:e; //获取活动
>I am currently confused about a piece of code that I have encountered:

[code]
function handleKeyUp(e){

e = (!e) ? window.event : e; //get the event



e = e || window.event;


e = e || window.event;



if(!e)

{

e =(typeof window!=" undefined"

&& typeof window.event!=" undefined")

? window.event

:null;

}


if(e)

{

// ...

}

if (!e)
{
e = (typeof window != "undefined"
&& typeof window.event != "undefined")
? window.event
: null;
}

if (e)
{
// ...
}


> target =(!e.target)? e.srcElement:e.target; //获取活动'
> target = (!e.target) ? e.srcElement : e.target; //get the event''s



target = e.target || e.srcElement;


target = e.target || e.srcElement;



*和*


if(target)

{

// ...

}

*and*

if (target)
{
// ...
}


e = e || window.event;就足够了。
e = e || window.event; will suffice.



它不会。

It won''t.


如果e是假的(例如未定义),e将获得对window.event的引用。
If e is falsy (e.g. undefined), e will get a reference to window.event.



将该值转换为布尔值的Iff类型转换不会引发异常。

Iff type-converting that value to boolean does not throw an exception.


由于各种浏览器DOM中的不同事件模型。
A necessity due to different event models in the various browser DOMs.



开始处理。

PointedEars

-

现实主义:HTML 4.01严格

福音:XHTML 1.0严格

疯狂:XHTML 1.1 as application / xhtml + xml

- Bjoern Hoehrmann


11月11日上午8:07,消失了<消失... @ gmail.comwrote:
On Nov 11, 8:07 am, disappearedng <disappeare...@gmail.comwrote:

function handleKeyUp(e){

e =(!e)? window.event:e; //得到活动

target =(!e.target)? e.srcElement:e.target; //得到活动的


1)这是一个活动吗?

2)e =(!e)的目的是什么? )? window.event:e; //获取事件
function handleKeyUp(e){
e = (!e) ? window.event : e; //get the event
target = (!e.target) ? e.srcElement : e.target; //get the event''s

1) Is e here an event?
2) what''s the purpose of e = (!e) ? window.event : e; //get the event



这里是事件对象。常规浏览器会将事件

对象作为事件处理程序的第一个参数传递。因此

''handleKeyUp(e)''代码。但IE的做法不同。它并不是
将任何东西传递给事件处理程序(这使得e未定义)而是

IE将事件对象实现为全局变量。因此

''window.event''的事情。所以,代码检查e是否是
''falsy''(和未定义的IS falsy),如果是,则将window.event分配给

e,否则将e分配给自己。写这个

的替代方法是:


/ *如果e是假的那么e是window.event * /

如果(!e){

e = window.event;

}


或我首选的写作方式


/ * e是e或window.event * /

e = e || window.event;


或者某些人甚至可能更喜欢


/ *如果e未定义则e是window.event * /

if(e == undefined){

e = window.event;

}

e here is the event object. Regular browsers will pass the event
object as the first argument to the event handler. Hence the
''handleKeyUp(e)'' bit of code. But IE does it differently. It doesn''t
pass anything to the event handler (which makes e undefined) instead
IE implements the event object as a global variable. Hence the
''window.event'' thing. So, the code is checking to see if e is
''falsy'' (and undefined IS falsy) and if it is, assign window.event to
e, otherwise assign e back to itself. Alternative ways to write this
are:

/* if e is falsy then e is window.event */
if (!e) {
e = window.event;
}

or my preferred way to write this

/* e is e or window.event */
e = e || window.event;

or some may even prefer

/* if e is undefined then e is window.event */
if (e == undefined) {
e = window.event;
}


3)if(if.nodeType == 3)

target = target.parentNode;''
3) What''s if (target.nodeType == 3)
target = target.parentNode;''



某些浏览器特别是基于Webkit的浏览器,如Safari和

诺基亚的S60平台网页浏览器有时会在文本节点而不是包含文本节点的节点上触发事件

。这个

通常不是你想要的。你通常想要的是知道

哪个< divor< spanor< petc。与事件相关联。因此,如果

我们得到一个文本节点(nodeType 3),我们感兴趣的真实节点
就是它的父节点。

Some browsers, particularly Webkit based browsers like Safari and
Nokia''s web browser for the S60 platform sometimes triggers the event
on the text node rather than the node containing the text node. This
is not typically what you''d want. What you''d typically want is to know
which <divor <spanor <petc. is associated with the event. So if
we get a text node (nodeType 3) the real node we''re interested in
would be its parent node.


这篇关于活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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