Disable link with the prototype observe method

百般思念 提交于 2019-12-06 20:20:56

问题


I want to create a link like this:

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

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

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; };

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

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

(which is quite logical).

Any ideas on how I could achieve this?

Thanks.


回答1:


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

or

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

or

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



回答2:


You have to use the event object to achieve this with prototype.

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


来源:https://stackoverflow.com/questions/1399613/disable-link-with-the-prototype-observe-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!