在IE 9中停止事件(不升级到Prototype 1.7) [英] Stop Event in IE 9 (without upgrading to Prototype 1.7)

查看:97
本文介绍了在IE 9中停止事件(不升级到Prototype 1.7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的网站使用Prototype 1.6.1。它的Event.stop()在IE9中不起作用。我知道Prototype 1.7解决了这个问题。但是,如果我无法升级到Prototype 1.7,是否有一个转发?

The site I'm working on uses Prototype 1.6.1. Its Event.stop() doesn't work in IE9. I know that Prototype 1.7 fixes the problem. However, is there a walk-around if I cannot upgrade to Prototype 1.7?

我需要该网站与IE 7,8和9(以及Chrome,Firefox等)兼容。

I need the site to be compatible with IE 7, 8 and 9 (as well as Chrome, Firefox, etc).

谢谢!

编辑:我试过 event.preventDefault()但它不起作用在IE 9中对我来说。这是一个例子: http://jsfiddle.net/garthcn/AdR7g/
它适用于jsfiddle / Chrome / Firefox。如果您将代码粘贴到HTML文件并使用IE9打开它,它将无法正常工作。

I tried event.preventDefault() and it doesn't work for me in IE 9. Here is an example: http://jsfiddle.net/garthcn/AdR7g/ It works in jsfiddle/Chrome/Firefox. If you paste the code to an HTML file and open it with IE9, it won't work.

EDIT2:我刚刚发现Prototype 1.6.1将自己的 preventDefault()方法添加到IE中在IE 9上工作。但是,IE 9有自己的 preventDefault(),它实际上有效。因此,如果我坚持使用Prototype 1.6.1,我想我无法在IE 9上使用 preventDefault()

I just found that Prototype 1.6.1 adds its own preventDefault() method to IE which doesn't work on IE 9. However, IE 9 comes with its own preventDefault() which actually works. So if I stick to Prototype 1.6.1, I guess I cannot get preventDefault() to work on IE 9.

推荐答案

function stopDefAction(evt) {
     evt = evt || event;
     if (evt.preventDefault) {
          evt.preventDefault();
     }
     else {
          evt.returnValue = false;
     }
}

这篇关于在IE 9中停止事件(不升级到Prototype 1.7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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