How to build simple tabs with jQuery?

前端 未结 6 762
感动是毒
感动是毒 2020-11-29 02:58

I have the following code: fiddle

Which works great in websites I create my self and with no JS the tabs act as jump links to the relevant sections. When placed in

6条回答
  •  时光说笑
    2020-11-29 03:44

    $(document).ready(function() {
    $("#content div").hide(); // Initially hide all content
    $("#tabs li:first").attr("id","current"); // Activate first tab
    $("#content div:first").fadeIn(); // Show first tab content
    $('#tabs li a').click(function(e) {
        e.preventDefault();
        if ($(this).attr("id") == "current"){ //detection for current tab
         return       
        }
        else{             
        $("#content div").hide(); //Hide all content
        $("#tabs li").attr("id",""); //Reset id's
        $(this).parent().attr("id","current"); // Activate this
        $( $(this).attr('href')).fadeIn(); // Show content for current tab
        }
    });
    

    });

    See Demo: http://jsfiddle.net/pradeepk00786/5ezT3/

提交回复
热议问题