以下代码为在菜单中单击的每个链接切换(插入和删除)类“menu-min”。我希望此脚本仅在单击 ID 为 #toggle-pane 的链接时才这样做。我不知道该怎么做。任何帮助表示赞赏。
<ul class="cbp-vimenu">
<li><a href="#" class="icon-logo"> </a></li>
<li>
<a href="#" class="icon-archive"><span class="menu-text"> Dashboard </span></a>
</li>
<li>
<a href="#" class="icon-search"><span class="menu-text"> Search </span></a>
</li>
<li>
<a href="#" class="icon-location"><span class="menu-text"> Location </span></a>
</li>
<li>
<a href="#" class="icon-images"><span class="menu-text"> Images </span></a>
</li>
<li>
<a href="#" class="icon-download"><span class="menu-text"> Download </span></a>
</li>
<li>
<a id="toggle-pane" href="#" class="icon-pencil"><span class="menu-text"> Add Class </span></a>
</li>
<!-- Example for active item:
<li class="cbp-vicurrent"><a href="#" class="icon-pencil">Pencil</a></li>
-->
</ul>`
这是我的 jQuery
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$( ".cbp-vimenu" ).click(function() {
$( this ).toggleClass( "menu-min" );
});
</script>