Showing content based on a nav link clicked

后端 未结 4 1349
长情又很酷
长情又很酷 2021-01-16 13:09

I have a menu selection that looks like this:

  • About
4条回答
  •  伪装坚强ぢ
    2021-01-16 13:20

    This solution assumes that the a elements will only have a single class.

    $('.menu li a').click(function (e) {
        e.preventDefault();
        $(".wrapper,.misc,.content,.about").hide(); // Hide all.
        $("." + this.className.slice(0,-3)).show(); // Show one based on the class
    });
    

    It binds the same handler to all the a elements.

    When clicked, it hides all the targeted elements, and then slices away the "Nav" from the .className to create a selector to choose the one to display.

    Not sure what .wrapper does, since it's not in your HTML.

提交回复
热议问题