the attribute “href” of a <a> tag is a URL,but it calls functions after clicking the <a> tag.How it works

空扰寡人 提交于 2019-12-13 08:52:49

问题


I found this question in jQuery UI demos.If you downloaded the jQuery UI,and so it located in "demos/droppable/photo-manager.html".

In this html page,there were several tags showing the delete icons in photo div.These tags' property named "href" are URLs,but it would call functions after clicking the tags. URLs->functions?How to do that?


回答1:


You can attach a click event to a link and null the browser's default behaviour.

HTML

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

jQuery

$('a').click(function(event) {
   event.preventDefault();
   func();
});


来源:https://stackoverflow.com/questions/7817422/the-attribute-href-of-a-a-tag-is-a-url-but-it-calls-functions-after-clicking

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