当当前链接用跨度标识时,我一直在尝试从列表中创建一个菜单,并且当我浏览网站时,我会在所有分支上显示父级别和当前级别。我对脚本相当陌生,非常感谢任何帮助示例如果列表是:AA b A bc A b
当前分支跨度在 c 上。我希望列表是:bbcb
-HTML 列表 -
<ul>
<li><span class="currentbranch0"><a href="/site/">Home</a></span>
<ul class="multilevel-linkul-0">
<li><a href="/site/news/">News</a>
<ul class="multilevel-linkul-1">
<li><a href="/site/news/internal/">Internal</a>
<ul class="multilevel-linkul-2">
<li><a href="/site/news/internal/archive/">Archive</a></li>
</ul>
</li>
<li><a href="/site/news/external/">External</a>
<ul class="multilevel-linkul-2">
<li><a href="/site/news/external/archive/">Archive</a></li>
</ul>
</li>
<li><a href="/site/news/poll/">News Poll</a></li>
<li><a href="/site/news/allnews/">All News</a></li>
</ul>
</li>
<li><span class="currentbranch1"><a href="/site/locations/">Locations</a></span>
<ul class="multilevel-linkul-1">
<li><a href="/site/locations/a/">a</a></li>
<li><a href="/site/locations/b/">b</a></li>
<li><ahref="/site/locations/c/">c</a></li>
<li><span class="currentbranch2"><a href="/site/locations/menutest/">Menu Test</a></span>
<ul class="multilevel-linkul-2">
<li><a href="/site/locations/menutest/test/">test</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
脚本
(document).ready(function() { var output = '<ul>';
output += $("#side_nav span").last().parent().parent().parent().parent().html();
output += '</ul>';
document.getElementById('side_nav').innerHTML = output;
});$("#side_nav li").ready(function() {
var count = [];
$("#side_nav ul[class^='multilevel-']").each(function(){
var item = $(this).attr('class')
count.push(item);
count.sort();
});
$('#side_nav li').each(function(){
if($(this).parent('ul').hasClass(count[count.length-1])){
$(this).remove();
};
});
});