使用原型观察方法禁用链接 [英] Disable link with the prototype observe method

查看:60
本文介绍了使用原型观察方法禁用链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个这样的链接:

I want to create a link like this:

<a href="http://example.com">text</a>

并替换行为,以便链接在点击时使用Ajax下载内容。

and replace the behavior so that the link downloads the content with Ajax instead when clicking.

重要的是我不要更换href属性(因此复制链接仍然有效)。

It is important for me not to replace the href attribute (so copying the link still works).

一个解决方案是要做的事情:

One solution would be to do:

$('link').onclick = function() { return false; };

但我想使用.observe方法。但这不起作用:

but I would like to use the .observe method. But this doesn't work:

$('link').observe('click', function() { return false; });

(这是合乎逻辑的)。

关于如何实现这一目标的任何想法?

Any ideas on how I could achieve this?

谢谢。

推荐答案

$('link')。observe('click',function(e){Event.stop(e);});

$('link').observe('click', function(e) { Event.stop(e); });

$('link').observe('click', function(e) { e.stop(); });

$('link').observe('click', Event.stop);

这篇关于使用原型观察方法禁用链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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