Clicking anchor should execute javascript not go to new page

前端 未结 5 677
忘掉有多难
忘掉有多难 2021-01-14 07:45

I have a HTML anchor that when clicked should make a div slide up or down (I call JQuery\'s .slideToggle(); function);

My Problem: When

5条回答
  •  醉梦人生
    2021-01-14 08:17

    Solution 1:

    HTML:

    Click me
    

    jQuery:

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

    Solution 2:

    HTML:

    Click me
    

    Solution 3:

    HTML:

    Click me
    

    Solution 4:

    HTML:

    Click me
    

    jQuery:

    $(function(){
        $("a").click(function(event){
            return false;
        }); 
    });
    

    Solution 5:

    HTML:

    Click me
    

提交回复
热议问题