我需要在选择 jquery 选项卡时将自定义 css 添加到它,如何?
我需要将 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我没有误解你的问题,你可以简单地执行以下操作:
If I don't misunderstand your question, you could simply do as following:
您可以将代码放在选项卡控件的
select
事件中http ://docs.jquery.com/UI/Tabs#event-select
You could put the code in the
select
event of the tab controlhttp://docs.jquery.com/UI/Tabs#event-select
哇啊!在这里过度扩张的事情!
好的,首先,jQuery 很棒,但它已经完成了工作。为了实现您想要实现的目标,您不需要任何类型的 JavaScript。使用简单的CSS。
观看:
至于我之前承诺的那个链接,这篇博文 更深入地了解“选项卡事件”“外部”当前选定选项卡的 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:
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".