给定一个父标签集,每个标签具有多个子标签集。如何创建链接“堂兄”内容的<a href="#??"></a>
?这是我到目前为止所尝试的,我并不认为它是正确的!我试图从tab 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>
答案 0 :(得分:1)
这样的事情会起作用:
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 );
}
}
});