我正在检查Classic ASP中是否有条件,但它无法正常工作。以下是无效的代码:
<% If (Request.QueryString("Cat")="") Then %>
<a class="home selected" href="/" alt="Home"></a>
<%Else%>
<a class="home" href="/" alt="Home"></a>
<%End If%>
这会显示两个锚标记,但我想只显示两个锚标记。
请告诉我如何修复它的建议。
答案 0 :(得分:1)
<%
''# 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>
答案 1 :(得分:0)
虽然我没有看到发布的代码有任何问题,但我更干净的方式:
<%
Dim Cat, Selected
Cat = Request.QueryString("Cat")
If (Cat = "") Then
Selected = " selected"
End If
Response.Write("<a class=""home" & Selected & """ href=""/"" alt=""Home""></a>")
%>