2011-09-01 39 views
1

我正在檢查經典ASP中的條件,但它不能正常工作。下面是一個不正常的代碼:如果/否則條件與OR子句在經典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

我剛剛測試過它,它的工作原理應該如此。 –

回答

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>") 
%> 
1

肖恩已經是在正確的方向,但一個步驟,但這個是一些包括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>