简体   繁体   English

如何使“切换器面板”的链接反映“显示”类?

[英]How do I make the link for Switcher Panel reflect 'show' class?

I am using jQuery Content Panel Switcher https://code.google.com/p/jquery-content-panel-switcher/ 我正在使用jQuery Content Panel Switcher https://code.google.com/p/jquery-content-panel-switcher/

By adding the class 'show', you can determine which content/panel shows on load, but how do I make that reflect in the links that choose the content/panel. 通过添加“显示”类,您可以确定在加载时显示哪些内容/面板,但是如何在选择内容/面板的链接中体现出来。

Basically, if panel 1 is show, link 1 should be red. 基本上,如果显示面板1,则链接1应该为红色。

I am already using this to change the link after the click 点击后,我已经使用它来更改链接

     $(document).ready(function(){
    $('.nav_buttons a').click(function(event){
        $('.nav_buttons a').css({ 'background-color' : '' }); //clear past selections
        $(this).css({ 'background-color' : 'red' }); //set new selection
    });    
  });

On first time page load just the default link that loads can be explicitly bind with a certain (css)class attribute and then on each click event the class attribute of the links can be changed accordingly using jQuery. 第一次页面加载时,仅加载的默认链接可以与某个(css)类属性显式绑定,然后在每次单击事件时,可以使用jQuery相应地更改链接的类属性。

First remove all the class attributes of the links 首先删除链接的所有类属性

$('.nav_buttons a').removeClass('selected');

Then add the specific css class that makes the navigation background color change 然后添加使导航背景颜色发生变化的特定CSS类

$(this).addClass('selected');

Here's a full demonstration on JsFiddle 这是JsFiddle上的完整演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM