如何设置活动到班级

时间:2015-02-21 12:13:42

标签: javascript asp.net-mvc c#-4.0 asp.net-ajax

我正在通过changeCulture方法更改语言;

public ActionResult ChangeCulture(Culture lang, string returnUrl)
{
    if (returnUrl.Length >= 3) returnUrl = returnUrl.Substring(3);
    return Redirect("/" + lang.ToString() + returnUrl);
}

这是html部分;

 <li class="currency-EUR">
    <a href="@Url.Action("ChangeCulture", "Home", new { lang = (int)SkycapGaming.Culture.Tr, returnUrl = this.Request.RawUrl })">TR</a>
    <input type="hidden" value="TR">
</li>
<li class="currency-USD">
    <a href="@Url.Action("ChangeCulture", "Home", new { lang = (int)SkycapGaming.Culture.En, returnUrl = this.Request.RawUrl })">EN</a>
    <input type="hidden" value="EN">
</li>

我想将有效设置为<li class="currency-EUR">当页面开启时,它应为<li class="currency-EUR active">

1 个答案:

答案 0 :(得分:1)

当你在url中传递语言时,你可以提取它,然后只需使用像

这样的javascript
var url = window.location.href; //this return full url: http://webiste.com/eur/something.html
url = url.split("/");
url = url[1];
if(url == "eur"){
   $(".currency-EUR").addClass("active");
   $(".currency-USD").removeClass("active"); // in case it was already set
}else{
  $(".currency-USD").addClass("active");
  $(".currency-EUR").removeClass("active");
}