点击高亮当前,取消同类的效果
需要点击的动作,一般加有交互动作的标签,如a,buttom等(雷哥说的)
二级导航菜单:http://www.cnblogs.com/hanxuming/p/5916504.html
给模版循环出来的li>a加事件(点击高亮当前样式):
<ul class="fmValUl" id="js-fmValUl"> <!--{loop $emots $key $value}--> <li id="fmValLi_{$key}" class="fmValLi" data-value="{$key}"> <a href="javascript:;" onclick="wz_dsu_set_qdxq('{$key}');">{$value['name']}</a> </li><!--{/loop}--> </ul>
<script type="text/javascript"> function wz_dsu_set_qdxq(key){ $("#js-fmValUl li").removeClass("fmValLiActive"); $("#js-fmValUl>li[data-value]").each(function(){ var k = this.getAttribute("data-value"); if(k == key){ $(this).addClass("fmValLiActive"); } }); } </script>