我需要在选择 jquery 选项卡时将自定义 css 添加到它,如何?

发布于 2024-10-29 03:28:52 字数 3199 浏览 1 评论 0原文

我需要将 .ui-state-active 、 .ui-widget-content .ui-state-active 的 css 修改为以下内容:

.ui-state-active , .ui-widget-content .ui-state-active {
     background-image: url('images/tab-over.png') !important;
}

但是,当我这样做时,我得到了所需的效果,但网站上的其他元素会受到影响点击。我只在单击选项卡时才需要此功能。

有更安全的方法吗?

这是我的 html 代码:

<div id="tabs">


    <div id="left-side">
    </div>



    <ul class="tab-menu">
        <li id="home">
        <a href="<%= Url.Action("GetCoreTab", "Tab") %>" class="a">
        <b>
            <div id="home" class="menu">
            </div>
        </b>
        </a>
        </li>
        <li><a href="<%= Url.Action("GetDatesAndLocationTab", "Home") %>" class="a"><b>
            <div id="dates-and-location" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetTariffTab", "Home") %>" class="a"><b>
            <div id="tariff" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetCustomerInformationTab", "Tab") %>" class="a"><b>
            <div id="customer-information" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetRatesAndChargesTab", "Tab") %>" class="a"><b>
            <div id="rates-and-charges" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetPaymentsAndVouchersTab", "Tab") %>" class="a"><b>
            <div id="payments-and-vouchers" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetDeliveryAndCollectionTab", "Tab") %>" class="a"><b>
            <div id="delivery-and-collection" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetGeneralTab", "Tab") %>" class="a"><b>
            <div id="general" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetEquipmentAndOtherDriversTab", "Tab") %>" class="a">
            <b>
                <div id="equipment-and-other-drivers" class="menu">
                </div>
            </b></a></li>
        <li><a href="<%= Url.Action("GetCustomerPreferencesTab", "Tab") %>" class="a"><b>
            <div id="customer-preferences" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetCustomerStatisticsTab", "Tab") %>" class="a"><b>
            <div id="customer-statistics" class="menu">
            </div>
        </b></a></li>
    </ul>

    <div id="right-side">
    </div>

</div>

I need to modify the css of .ui-state-active , .ui-widget-content .ui-state-active to the following:

.ui-state-active , .ui-widget-content .ui-state-active {
     background-image: url('images/tab-over.png') !important;
}

However, when I do that I get the desired effect but other elements on the website get affected when clicked. I want this function only when I click a tab.

Is there a safer way to do this ?

Here is my html code:

<div id="tabs">


    <div id="left-side">
    </div>



    <ul class="tab-menu">
        <li id="home">
        <a href="<%= Url.Action("GetCoreTab", "Tab") %>" class="a">
        <b>
            <div id="home" class="menu">
            </div>
        </b>
        </a>
        </li>
        <li><a href="<%= Url.Action("GetDatesAndLocationTab", "Home") %>" class="a"><b>
            <div id="dates-and-location" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetTariffTab", "Home") %>" class="a"><b>
            <div id="tariff" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetCustomerInformationTab", "Tab") %>" class="a"><b>
            <div id="customer-information" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetRatesAndChargesTab", "Tab") %>" class="a"><b>
            <div id="rates-and-charges" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetPaymentsAndVouchersTab", "Tab") %>" class="a"><b>
            <div id="payments-and-vouchers" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetDeliveryAndCollectionTab", "Tab") %>" class="a"><b>
            <div id="delivery-and-collection" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetGeneralTab", "Tab") %>" class="a"><b>
            <div id="general" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetEquipmentAndOtherDriversTab", "Tab") %>" class="a">
            <b>
                <div id="equipment-and-other-drivers" class="menu">
                </div>
            </b></a></li>
        <li><a href="<%= Url.Action("GetCustomerPreferencesTab", "Tab") %>" class="a"><b>
            <div id="customer-preferences" class="menu">
            </div>
        </b></a></li>
        <li><a href="<%= Url.Action("GetCustomerStatisticsTab", "Tab") %>" class="a"><b>
            <div id="customer-statistics" class="menu">
            </div>
        </b></a></li>
    </ul>

    <div id="right-side">
    </div>

</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放手` 2024-11-05 03:28:52

如果我没有误解你的问题,你可以简单地执行以下操作:

$('#tabs .tab-menu li a').click(function() {
    $('#tabs .tab-menu li').css('background-image', 'url("images/original-bg.png")');
    $(this).parent().css('background-image', 'url("images/tab-over.png")'; 
});

If I don't misunderstand your question, you could simply do as following:

$('#tabs .tab-menu li a').click(function() {
    $('#tabs .tab-menu li').css('background-image', 'url("images/original-bg.png")');
    $(this).parent().css('background-image', 'url("images/tab-over.png")'; 
});
痴情换悲伤 2024-11-05 03:28:52

您可以将代码放在选项卡控件的 select 事件中

$( "#tabs" ).tabs({
   select: function(event, ui) { 
     //ui.item has the current object for you.
   }
});

http ://docs.jquery.com/UI/Tabs#event-select

You could put the code in the select event of the tab control

$( "#tabs" ).tabs({
   select: function(event, ui) { 
     //ui.item has the current object for you.
   }
});

http://docs.jquery.com/UI/Tabs#event-select

怕倦 2024-11-05 03:28:52

哇啊!在这里过度扩张的事情!

好的,首先,jQuery 很棒,但它已经完成了工作。为了实现您想要实现的目标,您不需要任何类型的 JavaScript。使用简单的CSS。

观看:

/*  FYI: The following CSS selector can also be used to make changes 
    via JavaScript/jQuery to Currently selected tab.
    I have a blog post about that I'll list at the end of my answer */
.ui-tabs-selected {
    background-image: url('images/tab-over.png') !important;
} /* This will change the background of the 
     currently selected li element acting as the tab */

/*  If you would like to change the background or something of current panel,
    you would access it with the following CSS selector */
.ui-tabs-panel:not(.ui-tabs-hide) {
    background-image: url('images/tab-over.png') !important;
} /* This will change the background of the 
     currently selected div element acting as the panel */

至于我之前承诺的那个链接,这篇博文 更深入地了解“选项卡事件”“外部”当前选定选项卡的 ez 访问。

WHOA! Way over-extending things here!

OK, First of all, jQuery is great, but it has already done the work. To do what you are trying to achieve, you don't need ANY JavaScript of any kind. Use simple CSS.

Watch:

/*  FYI: The following CSS selector can also be used to make changes 
    via JavaScript/jQuery to Currently selected tab.
    I have a blog post about that I'll list at the end of my answer */
.ui-tabs-selected {
    background-image: url('images/tab-over.png') !important;
} /* This will change the background of the 
     currently selected li element acting as the tab */

/*  If you would like to change the background or something of current panel,
    you would access it with the following CSS selector */
.ui-tabs-panel:not(.ui-tabs-hide) {
    background-image: url('images/tab-over.png') !important;
} /* This will change the background of the 
     currently selected div element acting as the panel */

As for that link I promised earlier, this blog post goes into much more depth about ez access to currently selected tabs "outside" of the "tabs events".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文