是否可以将jQuery菜单链接到标签?
例如,如果用户在下面的菜单中选择“按过滤器”,我希望它打开“按过滤器搜索”选项卡。我怎样才能做到这一点?
JS
$("#menu").menu();
$("#search").tabs();
HTML
<ul id="menu" style="border: 0px; background:none">
<li><a id="2" style="cursor: pointer">Search</a>
<ul style="z-index: 2">
<li><a id="2a" style="cursor: pointer">By Filter</a></li>
<li><a id="2b" style="cursor: pointer">By Room</a>
</li>
</ul>
</li>
</ul>
<div id="search" style="z-index: 1;">
<ul>
<li><a href="#search-1">Search By Filters</a></li>
<li><a href="#search-2">Search By Room</a></li>
</ul>
<div id="search-1">
</div>
<div id="search-2">
</div>
</div>
答案 0 :(得分:1)
是的,你可以这样做:
为每个搜索选项添加ID
在菜单中设置Id 2的监听器,然后单击,调用
$('#tabid').click();
以下是完整的代码:
剧本:
$('#2a').click(function(){
$('#sbf a').click();
});
$('#2b').click(function(){
$('#sbr a').click();
});
HTML代码:
<ul id="menu" style="border: 0px; background:none; width:50%; ">
<li><a id="2" style="cursor: pointer">Search</a>
<ul style="z-index: 2">
<li><a id="2a" style="cursor: pointer">By Filter</a></li>
<li><a id="2b" style="cursor: pointer">By Room</a>
</li>
</ul>
</li>
</ul>
<div id="search" style="z-index: 1;">
<ul>
<li id="sbf"><a href="#search-1">Search By Filters</a></li>
<li id="sbr"><a href="#search-2">Search By Room</a></li>
</ul>
<div id="search-1">
</div>
<div id="search-2">
</div>
</div>
检查这个小提琴