Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...