最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent anchor link from being added to URL - Stack Overflow

programmeradmin5浏览0评论

I have a tabbed content box that when a tab is clicked, a '#div1' is appended to the end of my URL. Is there a way of preventing jQuery from doing this?

I still can't get it to work. I've made a fiddle...

/

I have a tabbed content box that when a tab is clicked, a '#div1' is appended to the end of my URL. Is there a way of preventing jQuery from doing this?

I still can't get it to work. I've made a fiddle...

http://jsfiddle/k6Ks8/

Share Improve this question edited Jan 27, 2012 at 14:53 Lightness Races in Orbit 385k77 gold badges665 silver badges1.1k bronze badges asked Jan 27, 2012 at 14:16 LiamLiam 9,85540 gold badges114 silver badges214 bronze badges 1
  • Please take more care over your posts. Punctuation matters. – Lightness Races in Orbit Commented Jan 27, 2012 at 14:53
Add a ment  | 

2 Answers 2

Reset to default 13

Sure, event.preventDefault() is what you are looking for.

http://api.jquery./event.preventDefault/

easy

    $(function(){
        $('a[href="#"]').click(function(event){
            event.preventDefault();
        });
    });
发布评论

评论列表(0)

  1. 暂无评论