If / Else condition with OR clause not working in Classic ASP
I am checking if condition in Classic ASP but its not working properly. Here is the code that isn't working:
<% If (Request.QueryString("Cat")="开发者_开发知识库") Then %>
<a class="home selected" href="/" alt="Home"></a>
<%Else%>
<a class="home" href="/" alt="Home"></a>
<%End If%>
This displays both anchor tags but I want to display only one from both.
Please give me suggestions on how to fix it.
Sean has taken is a step in the right direction but but this is some include asp isn't it, providing some kind of common navigation bar. Consider this approach.
<%
''# 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>
While I don't see any issue with the code that is posted, I cleaner way of doing this:
<%
Dim Cat, Selected
Cat = Request.QueryString("Cat")
If (Cat = "") Then
Selected = " selected"
End If
Response.Write("<a class=""home" & Selected & """ href=""/"" alt=""Home""></a>")
%>
精彩评论