如何设置为 class
How to set active to the class
我正在通过 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">
当您在 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");
}
我正在通过 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">
当您在 url 中传递语言时,您可以提取它然后像
一样使用 javascriptvar 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");
}