开发者

jQuery to select an item from a list?

I have a menu list something like this:

<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>

A currently selected list item has a class = "on". What I want to do is to find the next item in the list after the currently selected one, and set it's class to "on" and trigger it's "onclick", and set the current one to "off".

Any help appreciated!

update:

<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'开发者_如何学Go)" 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>


You can do this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜