如何使用jQuery在MVC3操作链接添加删除类? [英] How to use jquery add remove class in mvc3 action link?
本文介绍了如何使用jQuery在MVC3操作链接添加删除类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想补充类使用jQuery的东西所选的菜单。我尝试下面的方法,它不工作。
I am trying to add class for selected menu using jquery stuff. I tried the following method,its not working.
和我的code是
<div class="paragraph">
<ul class="tablinkss">
<li class="active">@Html.ActionLink("Login", "LogOn")</li>
<li>@Html.ActionLink("Register", "Register")</li>
</ul>
</div>
和我的jQuery
$(function () {
$('ul.tablinkss li').click(function () {
$('ul.tablinkss li').removeClass("active");
$(this).addClass("active");
});
});
谢谢,
推荐答案
Html.ActionLink
返回将有浏览器加载一个新的页面的超链接。 JavaScript就无法在这种情况下,除非你是preventing从加载下一个页面的链接工作。好了,它将为分裂工作,第二个则浏览器将显示新的页面。
Html.ActionLink
returns a hyperlink that will have the browser load a new page. JavaScript will not work in this case unless you are preventing the link from loading the next page. Well, it will work for a split second then the browser will show the new page.
- 登录激活。
- 用户点击注册。
- 注册,由于你的JavaScript激活。
- 浏览器加载寄存器页。
- 登录激活一次。
您需要在您的剃须刀模板,而不是在JavaScript来解决这个问题。
You need to fix this in your Razor template and not in JavaScript.
这篇关于如何使用jQuery在MVC3操作链接添加删除类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文