我有一些脚本在链接上创建了一个激活的CSS,但我有一个问题,我认为有很多IF的声明,有人可以帮我重构那段代码吗?
var link = window.location.pathname;
var currentPageName = window.location.href.match(/[^\/]+$/)[0];
var hl = $('#ih').val();
if (hl == 'True') {
var currentPageName = 'WVD';
}
if (window.location.href.indexOf("R") > -1) {
var currentPageName = window.location.href.match(/[^\/]+$/)[0];
}
if (window.location.href.indexOf("C") > -1) {
var currentPageName = window.location.href.match(/[^\/]+$/)[0];
}
if (location.pathname == "/") {
var currentPageName = 'MD';
}
$(".main-navigation ul li a").each(function () {
var link = $(this).attr("href");
if (link.indexOf(currentPageName) > -1) {
$(this).addClass("active");
$(this).css("color", "white");
$(this).css("text-decoration", "bold");
}
});