如何在ASP .NET MVC中使用jquery将css类应用于html元素? [英] How to apply css class to an html element using jquery in ASP .NET MVC?

查看:157
本文介绍了如何在ASP .NET MVC中使用jquery将css类应用于html元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个标签菜单,就像Stack Overflow中的一样。我创建了一个HTML列表,并将其设置为类似于使用CSS的选项卡菜单。我把HTML列表放在母版页上。现在,如何在用户点击列表后更改列表的颜色?

I'm trying to implement a tab menu just like the one in Stack Overflow. I created an HTML list and styled it to look like tab menus using CSS. I put the HTML list on the master page. Now, how do you change the color of the list once it's clicked by the user?

例如,如果单击堆栈溢出选项卡菜单,它将重定向到用户索引视图,然后更改选项卡的颜色菜单设置为橙色。如何实现这一点?

For example, if you click the Stack Overflow "Users" tab menu, it will redirect you to the "Users" index view, and then change the color of the tab menu to orange. How do I achieve this?

推荐答案

你不应该使用Jquery。原因是从您的描述中没有明确的理由来实际使用Javascript。

You dont and shouldnt use Jquery for this. The reason being is there is no clear reason from your description to actually use Javascript.

您需要在母版页上执行的操作是动态设置当前页的类按钮:

What you need to do on your master page is dynamically set the class of the current pages button to something like:

<li class="selected">Home</li>
<li>Users</li>
...

您可以通过访问

Request.Url

然后简单地创建一个CSS类来显示更改

Then simply create a CSS class to show the change

这里不需要javascript。我也喜欢JQuery,但太频繁人们尝试找到使用它的借口,而不是使用一个简单的更容易解决方案。请记住,不是每个人都可以使用Javascript

No need for javascript here. I love JQuery too, but too often people try and find excuses for using it, rather than using a simple more accessible solution. Remember not everyone can use Javascript

这篇关于如何在ASP .NET MVC中使用jquery将css类应用于html元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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