我有一个相当复杂(> 3k行)的经典ASP页面,它应该根据CountryID的值来抑制某些部分。我创建了布尔变量,如果Job的CountryID是特定值,则将它们设置为true。初始逻辑如下:
blnUSJob = False
blnCanadaJob = False
blnAUJob = False
blnNZJob = False
nCountryID = 0
If GetJobCountry(nJobAd_ID) = "CA" Then
blnCanadaJob = True
nCountryID = 2
End If
我已经创建了一个标记,如果blnCanadaJob评估为True,则呈现:
<%
if not blnCanadaJob then
%>
<tr>
<td width='30%' class='StandardLight' style="background-color:#dddddd"
valign='middle' align='right'>
<b>For replacement positions enter the following information for previous
incumbent</b>
<b>Name:</b><span class="Required">nbsp;*</span> <input type="text"
name="txtName" class="StdFieldName" value ="<%=strName %>" size="50" maxlength =
"50" /><br>
</td>
</tr>
现在,我需要确保为其他CountryID抑制此标记。实现这一目标的最佳方法是什么?我应该使用针对特定国家/地区ID的评估声明重复上述标记吗?或者,有更优雅的方式来处理这个吗?
感谢您的帮助和指导。
答案 0 :(得分:2)
如果您有更多选项,那么select语句最好(see here f.i。):
Select Case GetJobCountry(nJobAd_ID)
Case "CA", "US":
nCountryID = 2
blnCanadaJob = True
Case Else:
blnCanadaJob = False
End Select
您可以轻松地设置blnCanadaJob
等选项变量,并且更具可读性。
答案 1 :(得分:1)
您可以稍微简化一下:
if GetJobCountry(nJobAd_ID) = "US" then
%>
<tr>
<td width='30%' class='StandardLight' style="background-color:#dddddd"
valign='middle' align='right'>
<b>For replacement positions enter the following information for previous
incumbent</b>
<b>Name:</b><span class="Required">nbsp;*</span> <input type="text"
name="txtName" class="StdFieldName" value ="<%=strName %>" size="50" maxlength =
"50" /><br>
</td>
</tr>
%>
end if