简体   繁体   English

使用jQuery UI更改标签颜色?

[英]Changing tabs color using jquery ui?

I have tabs created using HTML and JQuery UI. 我有使用HTML和JQuery UI创建的选项卡。

PFB the link. PFB链接。

jsfiddle 的jsfiddle

$(document).ready(function() {
    //hiding tab content except first one
    $(".tabContent").not(":first").hide();
    // adding Active class to first selected tab and show
    $("ul.tabs li:first").addClass("active").show(); 

    // Click event on tab
    $("ul.tabs li").click(function() {
        // Removing class of Active tab
        $("ul.tabs li.active").removeClass("active");
        // Adding Active class to Clicked tab
        $(this).addClass("active");
        // hiding all the tab contents
        $(".tabContent").hide();       
        // showing the clicked tab's content using fading effect
        $($('a',this).attr("href")).fadeIn('slow');

        return false;
    });

});

Is it possible to change the color of the tabs? 可以更改标签的颜色吗?

Try like this http://jsfiddle.net/jogesh_pi/2Mzr5/6/ 像这样尝试http://jsfiddle.net/jogesh_pi/2Mzr5/6/

$(document).ready(function() {
    //hiding tab content except first one
    $(".tabContent").not(":first").hide();

    // adding Active class to first selected tab and show
    $("ul.tabs li:first").addClass("active").show(); 

    // Click event on tab
    $("ul.tabs li").click(function() {
        // Removing class of Active tab
        $("ul.tabs li.active").removeClass("active");
        $("ul.tabs li").removeClass("colorz");

        // Adding Active class to Clicked tab
        $(this).addClass("active");
        $("ul.tabs li").not( $(this) ).addClass("colorz");

        // hiding all the tab contents
        $(".tabContent").hide();       

        // showing the clicked tab's content using fading effect
        $($('a',this).attr("href")).fadeIn('slow');

        return false;
    });

});

Chrome ,右键单击并选择“ Inspect Element ,找到选项卡的类,然后进行更改。

Instead of removing adding active class or any other class that is being set by jqueryui , you must change it in jqueryui.css file. 您必须在jqueryui.css文件中进行更改,而不是删除添加活动类或jqueryui设置的任何其他类。 You can define additional classes against each color. 您可以针对每种颜色定义其他类。 Removing native classes is not a good idea. 删除本机类不是一个好主意。 You will need them at some point. 您有时会需要它们。 You can check css file in your browser by pressing F12 key and in right pane you can see styles. 您可以通过按F12键在浏览器中检查CSS文件,并且在右窗格中可以看到样式。 There you will find path of file that generated this style. 在这里,您将找到生成此样式的文件的路径。 If this css file is being loaded remotely, you can override your styles by adding !important poperty. 如果要远程加载此css文件,则可以通过添加!important poperty覆盖样式。 For example, to change color of .active you can do something like following code in your css files. 例如,要更改.active颜色,可以在css文件中执行以下代码。

.active{
     background: #FFF !important;
}

I think this a duplicate question to this. 我认为这是一个重复的问题。 Please follow this one to get the answer. 请按照此步骤获取答案。 How can i change the background color in jQuery.ui tabs 我如何在jQuery.ui选项卡中更改背景颜色

alternatively you can use: 或者,您可以使用:

CSS:

.ui-tabs .ui-tabs-nav
{
background: red;
}

.ui-tabs .ui-tabs-panel /* just in case you want to change the panel */
{
background: red;
}

You can create a css class: 您可以创建一个CSS类:

.red-background{
    background-color: red !important; /* important is required to override */
}

In your jquery call and add this class as required. 在您的jquery调用中,并根据需要添加此类。 For example: 例如:

$("ul.tabs li").addClass("red-background");

I have updated the fiddle for you: http://jsfiddle.net/2Mzr5/14/ 我已经为您更新了小提琴: http : //jsfiddle.net/2Mzr5/14/

You can change the background attribute of 您可以更改的背景属性

ul.tabs li 

in the css classes 在CSS类中

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

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