Asp classic 在asp中包含文件菜单活动页面彩色链接

Asp classic 在asp中包含文件菜单活动页面彩色链接,asp-classic,Asp Classic,我的书页太多了。当我更改菜单上的内容时,我必须更改每一页。我不想一次又一次地为每个页面编写导航菜单,所以我使用了include文件导航菜单。 我不太懂asp,但我想用它 navigation.inc示例: <a class="nav-link active" href="link1.asp">Link 1</a> <a class="nav-link" href="link2.asp">Link 2</a> 有一个类叫做active。将导航链

我的书页太多了。当我更改菜单上的内容时,我必须更改每一页。我不想一次又一次地为每个页面编写导航菜单,所以我使用了include文件导航菜单。 我不太懂asp,但我想用它

navigation.inc示例:

<a class="nav-link active" href="link1.asp">Link 1</a>
<a class="nav-link" href="link2.asp">Link 2</a>

有一个类叫做active。将导航链接绘制为蓝色。当我导航到link2页面时,我想这样做

<a class="nav-link" href="link1.asp">Link 1</a>
<a class="nav-link active" href="link2.asp">Link 2</a>

如何使用asp classic实现这一点?我试过一些东西,但看起来很可笑。有什么简单而专业的方法吗


感谢提供所有信息。

在所有页面中添加一个包含:

<%
...
%>
<!--#include file="nav.asp"-->
<%
...
%>
通过向vbscript添加自定义的
iif
函数,可以简化
nav.asp
页面

<%
function iif(condition, t, f)
    if condition then
        iif = t
    else
        iif = f
    end if
end function

curPageName = Request.ServerVariables("URL")
%>
<a class="nav-link<%=iif(curPageName = "link1.asp", " active", "")%>" href="link1.asp">Link 1</a>
<a class="nav-link<%=iif(curPageName = "link2.asp", " active", "")%>" href="link2.asp">Link 2</a>

在希望显示
导航
页面的页面中使用

navigation.asp:

<a class="nav-link" href="link1.asp">Link 1</a>
<a class="nav-link" href="link2.asp">Link 2</a>

然后使用一些jQuery来自动化链接上的“active”或“currentPage”类

<script>
    $(document).ready(function () {
        //Loop through all <a href> elements and see if it matches current page, if it does add "active" class to that link
        $("a").each(function () {
            if ($(this).attr("href") === window.location.pathname) {
                $(this).addClass("active");
            } else if ($(this).attr("href") === window.location.href) {
                $(this).addClass("active");
            } else if ($(this).attr("href") === window.location.pathname + window.location.search) {
                $(this).addClass("active");
            }
        });
    });
</script>

$(文档).ready(函数(){
//循环遍历所有元素,查看它是否匹配当前页面,是否向该链接添加了“活动”类
$(“a”)。每个(功能){
if($(this.attr(“href”)==window.location.pathname){
$(此).addClass(“活动”);
}else if($(this.attr(“href”)==window.location.href){
$(此).addClass(“活动”);
}else if($(this.attr(“href”)==window.location.pathname+window.location.search){
$(此).addClass(“活动”);
}
});
});
示例home.asp(带有各种“模板”——页眉、页脚、函数等):


<script>
    $(document).ready(function () {
        //Loop through all <a href> elements and see if it matches current page, if it does add "active" class to that link
        $("a").each(function () {
            if ($(this).attr("href") === window.location.pathname) {
                $(this).addClass("active");
            } else if ($(this).attr("href") === window.location.href) {
                $(this).addClass("active");
            } else if ($(this).attr("href") === window.location.pathname + window.location.search) {
                $(this).addClass("active");
            }
        });
    });
</script>
<% Option Explicit %>
<!-- #include virtual="/local/scripts/vbs/settings.asp" -->
<!-- #include virtual="/global/scripts/vbs/db.asp" -->
<!-- #include virtual="/global/scripts/vbs/format.asp" -->
<!-- #include virtual="/global/scripts/vbs/pages.asp" -->

<!-- #include virtual="/global/shared/templates/inc-doctype.asp" -->
<html lang="en">

<head>
<title><%=PageTitle & gWebTitle%></title>
<meta name="description" content="<%=TitlePageHeading%>">
<!-- #include virtual="/global/shared/templates/inc-meta.asp" -->
<!-- #include virtual="/global/shared/templates/inc-styles.asp" -->
<!-- #include virtual="/global/shared/templates/inc-scripts.asp" -->
</head>
<body>

<!-- #include virtual="/local/scripts/templates/header.inc" -->

<%
    'Main Page Content Goes Here
%>

<!-- #include virtual="/local/scripts/templates/footer.inc" -->

<script>
    $(document).ready(function () {
        //Loop through all <a href> elements and see if it matches current page, if it does add "active" class to that link
        $("a").each(function () {
            if ($(this).attr("href") === window.location.pathname) {
                $(this).addClass("active");
            } else if ($(this).attr("href") === window.location.href) {
                $(this).addClass("active");
            } else if ($(this).attr("href") === window.location.pathname + window.location.search) {
                $(this).addClass("active");
            }
        });
    });
</script>

</body>

</html>