jQuery从列表中选择一个项目?

时间:2010-03-03 01:54:40

标签: jquery

我有一个这样的菜单列表:

<ul class="submenuList"> 
  <li><a onclick="loadItem('Blue%20Orchid%20Press')" id="Blue%20Orchid%20Press">class="on">Blue Orchid Press</a></li>
  <li><a onclick="loadItem('Brilliant%20Telecommunications')" id="Brilliant%20Telecommunications" class="off">Brilliant Telecommunications</a></li> 
  <li><a onclick="loadItem('CBT%20Systems%201')" id="CBT%20Systems%201" class="off">CBT Systems 1</a></li> 
 </ul>

当前选定的列表项具有class =“on”。我想要做的是在当前选择的项目之后找到列表中的下一个项目,并将其类别设置为“on”并触发它的“onclick”,并将当前项设置为“off”。

任何帮助表示赞赏!

更新

<div id="menu">
    <div id="main_menu" style="display: block;"><ul><li><a onclick="loadSubMenu('f')" id="f" class="off">featured</a></li><li><a onclick="loadSubMenu('a')" id="a" class="off">advertising</a></li><li><a onclick="loadSubMenu('p')" id="p" class="on">print</a></li><li><a onclick="loadSubMenu('w')" id="w" class="off">web</a></li></ul></div>
    <br clear="all"><hr><br clear="all">
    <div id="sub_menu" style="display: block;"><ul class="submenuList"><li><a onclick="loadItem('Blue%20Orchid%20Press')" id="Blue%20Orchid%20Press" class="on">Blue Orchid Press</a></li><li><a onclick="loadItem('Brilliant%20Telecommunications')" id="Brilliant%20Telecommunications" class="off">Brilliant Telecommunications</a></li><li><a onclick="loadItem('CBT%20Systems%201')" id="CBT%20Systems%201" class="off">CBT Systems 1</a></li><li><a onclick="loadItem('CBT%20Systems%202')" id="CBT%20Systems%202" class="off">CBT Systems 2</a></li></ul></div>
  </div>

1 个答案:

答案 0 :(得分:3)

你可以这样做:

$("#sub_menu .on").removeClass("on").addClass("off").parent("li")
        .next().children("a").addClass("on").click();