[英]With Jquery-ui Tabs, using Parent tab sets and child tab sets, How do I link between tab 'cousins'?
给定一个父选项卡集,每个选项卡具有多个子选项卡集。 如何创建在“表兄弟”内容之间链接的<a href="#??"></a>
? 到目前为止,这是我尝试过的方法,但我并不认为这是正确的! 我尝试从选项卡id =#A.1跳转到表弟#E.2的每个链接都没有成功。
脚本:
<script> $(document).ready(function(event){
var tabs = $("#parentTabSet, #childSet1, #childSet2").tabs();
//here's what i've tried so far:
$(".interTabLink").click(function(event){
//this gets the `<ul><li><a href="#someId">tab user wants to see</a></li></ul>`
var ulLink =$(".anytabset").find("[href='"+$(this).attr("href")+"']");
//filter the 'var tabs' array to only have the tabset we want.
tabs.filter("#"+ulLink.closest("div").attr("id")).tabs("select", $(this).attr("href"));
});
});
</script>
的HTML:
<body>
<div id="parentTabSet" class="anyTabSet">
<ul>
<li><a href="#A">parent A</a></li>
<li><a href="#B">parent B</a></li>
<li><a href="#C">parent C</a></li>
<li><a href="#D">parent D</a></li>
<li><a href="#E">parent E</a></li>
</ul>
<div id="A">
<div id="childset1" class="anyTabSet">
<ul>
<li><a href="#A.1">foo</a></li>
<li><a href="#A.2">bar</a></li>
</ul>
<div id="#A.1"><p>insert your latin here</p></div>
<div id="#A.2">
<!--- this will link to cousin #E.2, with parent tab E --->
<a href="#E.2" class="interTabLink">more information here</a>
</div>
</div>
</div>
<div id="B">
<p>insert your latin here</p>
</div>
<div id="C">
<p>insert your latin here</p>
</div>
<div id="D">
<p>insert your latin here</p>
</div>
<div id="E">
<div id="childset2" class="anyTabSet">
<ul>
<li><a href="#E.1">foo</a></li>
<li><a href="#E.2">bar</a></li>
</ul>
<div id="#E.1">stuff</div>
<div id="#E.2">here</div>
</div>
</div>
</div>
</body>
这样的事情会起作用:
var mytabs = $('.anyTabSet').tabs();
$(".interTabLink").click(function( event ){
event.preventDefault();
var id = $(this).attr("href");
var tab = mytabs.find("li [href='"+id+"']");
if ( tab.length ) {
var tabset = tab.closest('.anyTabSet').tabs("select", id);
if ( tabset.length ) {
id = id.replace(/_[0-9]/,'');
tabset.parents('.anyTabSet').tabs("select", id );
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.