我如何应用class ="current"菜单项? [英] How do I apply class="current" to menu items?

查看:94
本文介绍了我如何应用class ="current"菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

如何将class ="current"应用于菜单项?

我知道如何以静态形式进行操作.

如何以动态方式将其应用于菜单项.

因此,单击菜单项时,会将class ="current"应用于

下面的代码


Hi Friends,

How do I apply class="current" to menu items?

I know how to do it in static form.

How would it be applied to a menu item in a dynamic fashion.

so that the menu item, when clicked, gets class="current" applied to the

below code


<li id="liFamily" class="current"><a href="">By Family</a></li>
<li id="liIndividual"><a href="#">By Individual</a></li>
<li id="liSeating" ><a href="#">By Seating</a></li> 



在这里我静态地应用,我想动态地做到这一点.



Here i apply statically, i want to do that dynamically

推荐答案

您必须使用选择器(A:link,A:visited,A:,A:hover).请查看本教程以获取更多详细信息.

CSS链接 [
You must use the selectors(A:link, A:visited, A:active, A:hover) of Anchor Tag. Check this tutorial for more details.

CSS Links[^]


您可以使用asp:ListView绑定到数据源.在itemtemplate中,可以在选择当前项目时添加class属性.
You can use a asp:ListView to bind to a datasource. In the itemtemplate you can add a the class attribute when the current item is selected.


在服务器端
您应该使用li添加"runat = server"属性

by server side
you should add "runat=server" attribute with li

<ul><li id="liFamily" runat="server" class="current"><a href="">By Family</a></li></ul>



现在您可以在服务器端访问此文件

如果您想在客户端进行操作
您应该在页面的最后使用javascript函数
您应该知道当前菜单,然后可以添加属性..
发挥globla的作用;并在最后一页的每个页面上调用函数
使用当前菜单.



Now you can access this on Server Side

if you want to do it on client side
you should use javascript function at the last of the page
and you should khow about current menu then you can add attribute..
make function as globla; and call function on each page at the last
with current menu.

function setmnu(mnuid)
{
   var mnu=document.getElementById(mnuid);
   mnu.className="current";
}
setmnu('liFamily');



好的



ok


这篇关于我如何应用class ="current"菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆