English 中文(简体)
Internet explorer 7/8支持正常事件传递,不需要window.event?
原标题:Internet explorer 7/8 support of normal event passing, no need for window.event?

众所周知,Internet explorer不支持将事件传递给像以下这样的事件处理程序函数:

function clickHandler(e) {
  // e is undefined in IE
  e = e || window.event;
{

令我惊讶的是,我发现事实上确实如此。我忘了在我的一个函数中使用“e=e||window.event”技巧,但它在IE8中有效!

我用IE开发工具做了一些测试,e对象已经完全定义好了,即使在IE7模式下也是如此。

我的问题是,既然我不喜欢8之前的IE版本,我应该完全放弃window.event吗?

最佳回答

如果使用DOM0属性方式分配事件处理程序,则仍然需要e=e|window.event位,如果您尝试访问e的属性,则会出现错误:

document.onclick = function(e) {
    e.cancelBubble = true; // Error
};

如果您使用<code>attachEvent</code>,那么您是对的,将向侦听器函数提供事件参数:

document.attachEvent("onclick", function(e) {
    e.cancelBubble = true; // No error
});
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签