我希望替换ul
父 ( li.filetabs
) 元素的子元素 ( ) 的类名。我所做的似乎很正确,但显然不是因为班级没有被替换。
用JSFIDDLE 更新 Jsfiddle 的注意事项:当您单击一次时,一切正常,再次单击相同的导航选项卡,您会看到下拉菜单消失并重新出现...
var aFileTabs = $('.filetabs');
var curTab = $(this);
// this seems to give correct output
var prevCurTab = $('.cTabActive').parent(); //(i.e. *jQuery(li.filetabs)* )
// the following line is the problem line; Ive tried replacing the children with
// $('ul',prevCurTab)... but that doesnt work either... I must be doing something
// very basic wrong
$(prevCurTab).children().removeClass('cTabActive').addClass('cPrevTabActive');
$('ul', curTab).addClass ('cTabActive');
编辑:抱歉,我忘记了 HTML,还有更多内容,所以只有前两个导航按钮 html 被显示以了解含义。
<div id="filemenu"> <!-- right tabs menu -->
<ul id="fm_ul">
<li class="filetabs">File
<ul>
<li class="m_items"><a href="#"><span class="aHeading">New</span><span class="shortcutK">Ctrl-U</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Open</span><span class="shortcutK">Ctrl-Z</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Save</span><span class="shortcutK">Ctrl-T</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Exit</span><span class="shortcutK">Ctrl-Q</span></a></li>
</ul></li><li class="filetabs">Edit
<ul>
<li class="m_items"><a href="#"><span class="aHeading">Undo</span><span class="shortcutK">Ctrl-M</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Redo</span><span class="shortcutK">Ctrl-S</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Zoom In</span><span class="shortcutK">Ctrl-R</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Zoom Out</span><span class="shortcutK">Ctrl-Q</span></a></li>
</ul></li>