Internet Explorer 7/8支持普通事件传递,不需要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 内容?
It is common knowledge that Internet explorer does not support event passing to event handler functions like this one:
function clickHandler(e) {
// e is undefined in IE
e = e || window.event;
{
For my surprise today, I found out that actually it does. I forgot to do this "e = e || window.event" trick in one of my functions, but it was working in IE8!
I did some tests with IE developer tools, the e object was fully defined and it was so even in IE7 mode.
My question is, should I drop the window.event stuff entirely since I do not care for IE versions prior to 8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 DOM0 属性方式分配事件处理程序,那么您仍然需要
e = e || window.event;
位,如果您尝试访问e
的属性,您将收到错误:如果您使用
attachEvent
那么您是对的,事件参数提供给监听器函数:If you assign an event handler using the DOM0 property way, then you still need the
e = e || window.event;
bit and you'll get an error if you try and access a property ofe
:If you use
attachEvent
then you're right, the event parameter is provided to the listener function: