我正在检查是否在经典ASP的条件,但它不能正常工作。下面是不起作用的代码:
<% If (Request.QueryString("Cat")="") Then %>
<a class="home selected" href="/" alt="Home"></a>
<%Else%>
<a class="home" href="/" alt="Home"></a>
<%End If%>这两个锚标签都会显示,但我只想显示两者中的一个。
请给我一些如何修复它的建议。
发布于 2011-09-02 10:17:02
虽然我没有看到发布的代码有任何问题,但我用更简洁的方式做到了这一点:
<%
Dim Cat, Selected
Cat = Request.QueryString("Cat")
If (Cat = "") Then
Selected = " selected"
End If
Response.Write("<a class=""home" & Selected & """ href=""/"" alt=""Home""></a>")
%>发布于 2011-09-02 19:33:35
Sean已经朝着正确的方向迈出了一步,但这是一些包括asp的,不是吗,提供了某种类型的导航栏。考虑这种方法。
<%
''# Some where at the top of the include we have a set of utlity functions
Function GetSelectedClass(cat)
If (Request.QueryString("Cat") = cat) Then
GetSelectedClass = " selected"
End If
End Function
''# Other utility functions here
%>
<!-- Here we start the common navigation HTML -->
...
<a class="home <%=GetSelectedClass("")%>" href="/" alt="Home"></a>
<a class="tables <%=GetSelectedClass("tables")%>" href="/List.asp?Cat=tables" alt="Tables"></a>
<a class="chairs <%=GetSelectedClass("chairs")%>" href="/List.asp?Cat=chairs" alt="Chairs"></a>https://stackoverflow.com/questions/7272422
复制相似问题