我整个上午都在努力尝试将下拉菜单添加到我页面上的简单选项卡式内容中。 我希望在用户单击选项卡时显示下拉菜单(包含 4 个元素)。下拉菜单应保持可见,直到用户点击另一个选项卡。
知道如何在下面实现它吗?我想这很容易...
非常感谢!
<style type="text/css">
ul.tabs {
margin: 0;
padding: 0;
float: left;
list-style: none;
height: 32px;
border-bottom: 1px solid #e9e9e9;
border-left: 1px solid #e9e9e9;
width: 100%;
}
ul.tabs li {
float: left;
margin: 0;
cursor: pointer;
padding: 0px 21px ;
height: 31px;
line-height: 31px;
border: 1px solid #e9e9e9;
border-left: none;
font-weight: bold;
background: #EEEEEE;
overflow: hidden;
position: relative;
}
ul.tabs li:hover {
background: #4b4b4b;
}
ul.tabs li.active{
background: #FFFFFF;
border-bottom: 1px solid #FFFFFF;
}
.tab_container {
border: 1px solid #e9e9e9;
border-top: none;
clear: both;
float: left;
width: 100%;
background: #FFFFFF;
}
.tab_content {
padding: 20px;
font-size: 13px;
font-family: arial;
color: #4b4b4b;
display: none;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$(".tab_content").hide();
$(".tab_content:first").show();
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active");
$(this).addClass("active");
$(".tab_content").hide();
var activeTab = $(this).attr("rel");
$("#"+activeTab).fadeIn();
});
});
</script>
<html>
<ul class="tabs">
<li class="active" rel="tab1">TAB1</li>
<li rel="tab2">TAB2</li>
<li rel="tab3">TAB3</li>
</ul>
</html>
最佳答案
好吧,从头开始我刚刚做的,然后检查这个。我认为它可能更适合你所追求的。 jsfiddle
如果您愿意,可以将 a 标签更改为 li!
要编辑事件标签的外观,请注意:
.active_tab{
}
并编辑标签内容编辑的外观:
.tabCont{
}
希望这次是对的!
关于javascript - 如何将子菜单添加到我的选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25307763/